« first day (4351 days earlier)      last day (819 days later) » 

00:04
SE have announced that they are making some big enhancements to the Bookmarks feature. meta.stackexchange.com/q/382019/334566 It looks good, but there's considerable controversy about the proposed name change.
How can you call something a "save" if it's not actually a permanent copy, and may be deleted by others?
 
5 hours later…
05:29
what is the significance of using, "from .abc import xyz as xyz" it's same as "from .abc import xyz"
05:44
none, run both lines with the disassembler will produce exactly the same thing
>>> dis.dis('from .abc import xyz as xyz')
  1           0 LOAD_CONST               0 (1)
              2 LOAD_CONST               1 (('xyz',))
              4 IMPORT_NAME              0 (abc)
              6 IMPORT_FROM              1 (xyz)
              8 STORE_NAME               1 (xyz)
             10 POP_TOP
             12 LOAD_CONST               2 (None)
             14 RETURN_VALUE
06:04
Though as it turns out, PEP-0484 has this particular thing to say about this syntax, basically the import using the ... as ... syntax is used to identify a imported name that should be exported back out, so somehow this is an additional thing for type hinting.
06:16
@metatoaster thanks, just saw this way of importing in fastapi, so was curisous on this
Yeah, turns out I had prematurely closed the relevant thread three months ago, so thank you for bringing that back up here
Though really the original question asked for the "difference", not the "why/reason" which meant my brain just said no, it's been asked and be done with it
06:32
@metatoaster adding fastapi tag to the question would be great, dont know if sterlite is used elsewhere or not
Nah, this is strictly a Python issue; imo the way they did this makes it all too confusing but like everything with type-hinting in Python, it's just a force-fed retrofit so whatever
In fact it was just removed by @KarlKnechtel
otherwise this would include every single package that has this syntax, which is probably not what we want
though maybe the mypy tag should be included...
06:56
there may well be other libraries that do this, for the same reason; and there's no reason why a FastAPI expert would have any special insight into why this code looks like that.
I was about to cast a close vote when I saw the comment section, but yeah. Today I learned something interesting (and my attitude towards type-checkers grew more negative).
that said, I'm amazed that there was that close of a duplicate
it seems like the kind of thing where, if you don't have the skill to check what the effect is, why does it occur to you to ask?
> Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form.
Key word: stub
i.e. a file with a .pyi extension
It's still a terrible idea, but at least it only affects a small subset of python files
07:35
Except mypy took it even further and treats .py files the same way, i.e. names must be re-exported either using __all__ (which has been the standard) or the ... as ... syntax (which is terrible)
@KarlKnechtel As a matter of fact, I did close that question as a duplicate of the two referenced question 3 months ago but given the discussion I searched and found that and saw the comment, and was like, oh wait, wtf, that is now a valid use case?!? So I decided to actually research and write a well-formed answer - as I noted in the comment, asking for "what is the difference" as it was originally meant I saw no difference, but it should have asked "why" which clued in something "deeper"...
@roganjosh ☺️
I should probably go check the repo again, then. ^^
But yes, my attitude towards typing and type hinting in Python grew even more negative with this mess, because seriously why, also stop trying to hamfist informal specification as if they are formal ones when the underlying interpreter/vm/runtime don't actually treat it that way
Disclaimer: May contain unexploded bombs and cat hair.
@metatoaster That's kind of the point of types. It would be pretty bad if every dict[str, list[int]] where some contract the interpreter has to check.
No, I mean, my position has been type-hinting in Python feels hamfisted in; if I want types that work I would use a language that has strict+strong typing, not Python, not TypeScript.
Python innately does not care, it will run regardless of whatever was actually assigned to the name, until it encounters something that it can't do and it raises whatever appropriate Exception
Meh. If I wanted everything that I actually wanted I would not be using any language.
07:46
Which also means oftentimes if the type-hinting and checker fails with false postive or false negative there are added costs for negative benefit because of mismatch between the type checker and the actual run-time
Fair, computers never really worked anyway (see: CPU bugs)
Which is why I don't care for type-hinting when I write Python, the "guarantee" is a lot of added cost for zero benefit at the run-time level (I am not saying it does not help with development, just that it's a lot of added cost when the underlying running interpreter doesn't care at all)
Don't get me wrong, I've been working with typing long enough to have a laundry list of yuck. But it's a clear net benefit in my book.
which is kind of what I hinted at (not saying it does not help with development - it totally does), but I just have a personal disgust reaction whenever I see some form of perceived layer violation
though as I said previously, I largely moved on from Python development whenever I can help it
Aren't docstrings also kind of a layer violation? Python doesn't really use them for anything, outside of the help function. I don't see anything wrong with being able to add metadata for other tools (and other programmers) in the code
I mean, in terms of how type checking isn't part of the run-time when it really probably should
but also, yes, certain usage docstrings can result in layer violation, and has cause some interesting bugs
namely trying to run code that uses unittest to setup doctests with python -OO in > Python 3.9 (maybe 3.8?) will result in the doctest module blowing up
the Bindings for the entire C standard library sounds nice if it's as good as I hope it is
@roganjosh "Bringing the hell of pointers to Python", "Why would you ever need this", ... I like their attitude.
My favourite is "Features: -Segfaults"
Same, heh
 
2 hours later…
Anonymous
10:23
@decorator
def a_function():
    def b_function():

    def c_function():

Is there any way to list the inner methods from within the decorator implemenation?
Anonymous
That is, find all methods inside a method
You could try source code or bytecode inspection.
Yeah, dis.dis shows that a_function would have MAKE_FUNCTION instructions.
Anonymous
What do you mean by dis.dis?
You can also look for code instances in the function's constants
>>> a_function.__code__.co_consts
(None, <code object b_function at 0x000001EFA5D13890, file "untitled.py", line 6>, 'a_function.<locals>.b_function', <code object c_function at 0x000001EFA5D254D0, file "untitled.py", line 9>, 'a_function.<locals>.c_function')
Anonymous
Aaah, I see. Thanks for putting me into the right direction!
10:29
Just remember, if a cop shows up, my official answer was "no, this isn't possible"
Anonymous
Haha, so you shouldn't do this, is that what you mean? :D
I'm not gonna go that far, but you should think about if you really want to do it
Anonymous
Well, ok, I'm currently building a small test framework and I want to be able to have some decorators inside it called "@framework.suite" and "@framework.test". If a method has the decorator "suite", it should find all the inner methods with the decorator "test".
Anonymous
Sooo, that's why I'm trying to find all methods at runtime
Any reason you're not just using classes to put the methods inside?
10:32
Aren't you just reinventing a class?
I wonder how outdated this is now stackoverflow.com/q/32611619/2301450
But yes, why not use a class
FWIW, if the suite itself is safe to execute you might just want to run it. That would let any internal function definitions and decorators run so nested @test could announce themselves.
if you're not sure it's safe to run, you can use the ast module, but that may or may not complicate things
Anonymous
Okay, this is the purpose for why I wanted to have it this way:

I already have a "TestSuite" class and a "TestCase" class. As of right now, you need to register each test inside a specific suite and I just wanted to hide this part and do it automatically "behind the scenes" so to say.
Anonymous
So the "@framework.suite" registers all tests automatically.
10:42
But why do you have functions in a function?
Anonymous
@framework.suite("Collection of A tests")
def collection_a_tests():

    @framework.test
    def t1():
        pass

   @framework.test
    def t2():
        pass

   @framework.test
    def t3():
        pass
Anonymous
@framework.suite("Collection of B tests")
def collection_b_tests():

    @framework.test
    def t1():
        pass

   @framework.test
    def t2():
        pass

   @framework.test
    def t3():
        pass
Anonymous
I want to be able to do something like this, separate collections of tests by using decorators.
Anonymous
But yeah, it's kind of weird. I'm going to rethink everything I think!
Can't you just replace def collection_a_tests(): with class collection_a_tests():?
10:46
Probably worth pointing out: Pytest rewrites the entire test program, so your desired level of introspection isn't over the top for testing.
Anonymous
@MisterMiyagi Hmm, do you mean that I shouldn't mimic Pytest?
No, just musing that it's pretty okay to do this for testing.
Wouldn't recommend it for normal programs, though.
Anonymous
Alright, thanks for the feedback. This is a python port for a testing framework made in C++, aimed at game development, so I'm in the process to redo everything in Python, which is why I'm coming here with the weirdest questions ever! :D
Perhaps macropy is suitable for your needs. This could well match the use of templates or macros in C++.
Anonymous
That seems interesting. Going to take a look at that! :)
11:08
macropy seems to use AST internally to do what it's doing, just fyi
I guess it's easier than directly using the ast module though (especially in this case with the decorators)
11:19
stackoverflow.com/questions/34295901/… Why did this question come up in "recently active", before I closed it? I can't find another change since last November.
oh, looks like it's a self-edit on one of the answers.
11:37
Might be a stupid Q, but I don't find any good information about this. How can I COMFORTABLE install packages with pip from different sources. Lets say I want to download a package from "pypi.org" and another package that I have created and hosted in AWS CodeArtifact. Is there a way to comfortable link this in a requirements.txt so that pip knows which package to download from which source?
requirements.txt is fed practically verbatim to pip as commands, so if you know the pip command you are good to go.
ah ok, thanks.
One more Q. As I´m working behind ZScaler in my Company... when I want to download a package from pypi.org I need to set a certificate in pip-config in order to be allowed to do the request. But When I´m using CodeArtifact there is an exception in our Company (ALL AWS services) and therefore I dont need a Certificate to do the request. Is there a better way than always comment in & out in the config file the cert="" option?
except adding an upstream to pypi.org in my self hosted artifact repository
@elsololobo What happens if you leave the certificate where it is and run it in your no-cert-required environment?
11:50
To make a terrible analogy, "a car doesn't need a license plate when it's in your garage" does not imply that you should remove the license plate from your car whenever you put it in your garage
@Kevin I will run into "SSL: CERTIFICATE_VERIFY_FAILED"
OTOH, "The License Plate Maniac lives in your garage and attacks you whenever you park a car with a license plate in your garage" is a very good reason to remove your license plate
@NordineLotfi Thanks for the answer, I´ll check if this might be a workaround
@PM2Ring I was looking at that very page earlier, but I didn't read far enough. Nice find.
12:08
@elsololobo As a step up from modifying the file manually, perhaps you could use the pip config command to set and unset the cert option from the command line. Maybe you could even get ZScaler and CodeArtifact to run the commands for you.
I'm not completely sure what ZScaler and CodeArtifact are, so I'm not making any definite promises
I wonder if it would be useful to edit the site-level config file... Hard to say with my fuzzy understanding of the environment
@elsololobo you can create config whille which can connect with the pypi and your private artifact , and when you install package using pip then you can switch between these artifact
@sahasrara62 any link/ documention I can follow on this?
thanks a lot, I´ll take a look <3
pip config can create config files for you, FWIW
12:34
is there a good hashing function that can convert an arbitrary string to a guid?
Anonymous
Has anyone used jinja2 here?
Anonymous
Why does include statements make html formatting weird?
Strictly speaking, any hash function that returns a fixed-size value for an input of any size, can't convert every possible string to a truly unique id
no no it can be lossy (there can be collisions)
but like you'd want to minimize them
Ok.
I'm sure you've considered this already, but how about the built-in function hash?
12:38
it's great but I've got a thing for guids
I guess I could convert from that numeric value to the guid
If by "guid" you mean "a string containing 32 hexadecimal (base-16) digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters", we could certainly make one of those
Looks like you only need 128 bits then. md5 would work for that, or practically any other hash from hashlib.
okay I'm going to tinker
12:59
Moderately silly approach: pastebin.com/raw/ARLMD1r4
That's almost exactly what I had, but better!
I hadn't thought to join the strings with -, that simplifies nicely
join is a lovely method, one of my favorites
13:55
To my friends in the US - is it common for large manufacturing companies (think global oil company) to own a rail line? From what I can see, it's common for railways to be owned by the companies that built them way back when, but what's not so clear is the kind of numbers of companies that did this i.e. are there company-owned railways all over the place, or did just a handful of companies actually build them?
As a non-expert, I don't have much notion of who owns a rail line. If I'm planning a trip, I might know which rail companies offer trips over some particular route. For example, "I can get from New York to Chicago using Amtrak".
Whether Amtrak owns the land and the metal over which I am riding, I couldn't say
Amtrak is govt. owned I think - one of the few that seems to be
I know that domestic travel makes use of freight rail lines outside of Amtrak but it's hard to gauge how extensive that network is
Wikipedia largely agrees -- "Founded in 1971 as a quasi-public corporation to operate many U.S. passenger rail routes,[1][2][4] Amtrak receives a combination of state and federal subsidies but is managed as a for-profit organization"
rounds down to "govt owned" for my purposes
My gut reaction to "global oil company XYZ owns a rail line" is, "sounds like something a rational/evil corporation would do, sure"
There's a prospect I might be routing trains for one of these companies but I lack the detail at the moment, so I'm trying to gauge (get it?) where I should be on the "OMG hit the brakes" scale. I just do trucks and cars
roganjosh singlehandedly destroys the oil economy by making its trains trace out funny shapes instead of going to their destinations
14:05
Part of me is intrigued; if the company doesn't own the lines etc. then there would be a better chance that the solution need only allocate quantities of stuff to pre-timetabled trains with fixed capacity. If they own the trainline and the carriages... that becomes significantly more complicated
this is why you just "eminent domain" all the core infrastructure or at least make all infrastructure owners share right of way
To directly answer the question of "how many large manufacturing companies have their own rail line?", my honest estimate is "not many"
This is based on 15% facts, 85% tea leaf divination
The tea leaves appear to be giving favourable indications - I'll take it
@PeterT eminant domain seemed always weird to me, because "just" compensation for an immaterial thing like land is infinity, because you have no costs associated to land and you keep it forever. Compared to things which have maintenance costs and thus have a finite value, rights to domains seem to have infinite value and thus can't be justly compensated for, also why they should be state owned :)
14:23
A cynic might say that the sole useful function of the government is to help its citizens overall by harming a smaller subset of its citizens
From that perspective, the government doesn't need to give you "just" compensation. They only need to pay you enough money so you don't go mad and burn down Chicago
ofc it is :) And I don't see why you have to be a cynic for that, it's working as intended. Many natural processes lead to local optima, whereas global rational planning can lead to global optima. I think this is the main reason why many programmers are flirting with some forms of socialism. Only way to have global optima is to have global planning, can't have that efficiently with markets alone
A functional global planner is a nice solution to Prisoner's Dilemmas
Hi guys!, I have a problem with my code but I'm not able to ask any questions on SO so I'm asking it here :P (It's a code to run through all the sites on SE and find which ones have a bounty size of 50)
@Kevin Which brings us to game theory and would imply that it is worth it to seem crazy :P
@DialFrost Welcome
14:28
@Kevin I think they were here before
revised message: Welcome back
If anyone wants to help me (I have to sleep now unfortunately but you start a chat with me as I don't want to clutter the main room :P)
14:49
If the goal is to determine whether 50 points is a valid amount to put up for bounty on a particular site, perhaps you can get valid bounty sizes by inspecting the html of https://puzzling.stackexchange.com/posts/bounty/1. That's the popup box that appears when you click the "start a bounty" button.
If the goal is to determine whether a site currently has at least one question with an active bounty of 50 points, I don't know how to do that.
Maybe you can get that data from data.stackexchange.com/stackoverflow/query/new
15:05
what are your opinions about conditional imports? I don't like them, ofc the other guy wants to use them
Conditional imports? What's the condition?
Hardware configuration, if using hardware a,b,c import implementations a or b or c. All the implementations are written, so they can all be loaded and they are small, he wants to only load the one which is needed, which looks ugly to me, because instead of having it at the top, you have it in the init of an object
15:21
The import inside the class confuses me. Why can't it be in the global scope, and what does the constructor do with the imported modules? I was envisioning something similar to how the os.path module is either posixpath or ntpath depending on your OS - you import one of X modules, but then assign it to a well-known, unchanging name. Can't you do it like that?
@Aran-Fey yes, I actually should do it like that, good point. The problem is that only in the object constructor do you really have the config available to see what should be chosen, but I guess that could be changed
I'm all for doing imports ASAP and checking static conditions then. Doing them in functions is asking for sneaky errors.
Agreed. Your hardware won't change during runtime, so all those checks should be global and only happen once
15:49
your hardware don't change during runtime in 99.9% of cases (unless hotswap is a prominent feature of your motherboard, or you are just crazy) but some people might want to bundle conditional action depending on which computer's hardware it's run on, so they don't have to create N different versions for each hardware
also in the import cases, which is a bit weird, it's probably because they bundled custom code on an external import
16:04
Every once in a while I do import inside of a function, if that function is the only place I will ever need the module.
"imports should always go at the top of the file because then you can use them anywhere" isn't a very strong justification, in my mind. It's about as convincing as "you should always declare your variables at the top of the scope, even if you don't use the variable for hundreds of lines"
I have digressed from the topic somewhat. In the specific case of having an import statement inside an if block that depends on your environment settings, I'd put that at the top of the file.
16:21
The primary reason to put imports at the top of the file is because code is read more than it is written, and that is where people expect to find them.
17:10
Not me, I'm built different
17:51
I wouldn't say that there is anything bad about "runtime imports" per se. It's just that they are only ever needed in situations where the added magic is guaranteed to be a footgun.
I dislike functions with import statements inside them so much :( Because one of the main use case for them that I've noticed is to avoid circular imports
In a perfect world, you will come to need fancy environment-specific logic because your project has grown in popularity. And simultaneously, your development team has attracted quality talent because your project has grown in popularity. So the added footgun danger is canceled out by the added footgun avoidance expertise.
In the fifteen seconds I took to write that message, I thought of about eight different catastrophe scenarios that happen in our world, and do not happen in a perfect world
Possibly controversial opinion: Python does not have circular imports.
When you import a file for the first time, an empty module object gets added to the sys.modules dict, and only then the contents of the file executes. Subsequent imports will just fetch the module object from sys.modules. So it's (nearly?) impossible for the body of a module to execute more than once
18:44
@Kevin Someone, somewhere, out there is fiddling with sys.modules right now to prove your statement utterly wrong. :O
This raises the question: Why does nobody ever say "somewhen"?
Somewhen, I, right here, will/have fiddle(d) with sys.modules to prove Kevin utterly wrong
[The room sighs, thinking "Oh no, it's another one of Aran's weird episodes"]
that "somewhen" just made me question a bunch of things I likely didn't want to question
Speaking of time, I learned about an interesting theory recently. The theory is that the world never actually changes; the world is just a 4-dimensional object, and as time passes, we see a different 3d slice of it than we saw before
but wait, this also raise the question: if people start saying somewhen when are you gonna say somewhy
@Aran-Fey are there seasons? if so I'll bring popcorns
The production schedule is all over the place, but the program will continue until I'm kicked/banned from this room :P
18:59
@MisterMiyagi I would like to be proven utterly wrong on this. I think it would reveal lots of interesting fiddly bits of the Python engine that I could play with.
Like turning over a big rock and seeing a hundred kinds of invertebrate. There's a whole ecosystem under there.
@Aran-Fey nice, that means I'll need to stock up on more popcorn then. Don't think I'll have enough
Depending on your definition of "module", the same "module" can be run twice (or more often) under different names. For example, import a.b.c, import b.c and import c could all refer to the same file
@Kevin there this?: stackabuse.com/python-circular-imports if you want a "possible" canonical, stackoverflow.com/questions/744373/… and maybe an example where there an actual error with the word "circular import" in it: stackoverflow.com/questions/70644414/…
and "how to avoid it" but I think that's already covered by the canonical I already posted above: stackoverflow.com/questions/7336802/…
@Aran-Fey A sensible self-consistent model of the world. Though I don't know if it helps you make any interesting predictions about reality. A bit like theorizing that the order of the operands for "/" should be the other way around. Putting the denominator on top doesn't let you do cooler math.
Agreed, it's not very useful for predictions. It was actually a counter-argument for the argument from change
(It basically says God is the source of all change in the world)
It's a very on-brand counter-argument for an atheist. "I don't believe in god, nor do I believe in change!", basically
19:13
Hmm, reminds me of a philosophical question that asks: is there any meaningful difference between a system that "exists", and a system whose behavior can be perfectly predicted from its starting state and rules?
To ask the question in a different way, If a computer program takes no input and produces no output, does anything "change" when you run the program? Not just in an objective sense, but in any subjective or immaterial sense that you like
What about the "perfectly predictable" part though? If the program doesn't produce output, what are you predicting?
Isn't this equivalent to asking "Is there a difference between a red shirt and a XXL shirt"? Those are two completely independent properties, no?
For example, when you run the program i = 1; while True: i += 1, you can confidently predict that an hour later the value of i will be larger than zero
19:29
There are too many undefined variables here IMO. What's "output", what's "existence", etc
The mathematical universe hypothesis predicts that our own reality is a predictable system (although the math to actually predict anything might be super difficult, thanks to quantum). If our reality is somehow more "real" than any sensible hypothetical reality, one explanation is that God (or something like Him) is powering our reality while the others lie dormant.
To take a page from the simulation hypothesis, our program is running and the others aren't
@Kevin I see, that clears things up a bit. Still, I find it interesting (and weird) that they set determinism as a prerequisite for existence. That looks like a completely unfounded assumption to me
@Aran-Fey same here. if we are able to think anything of anything, then spinning things a bit by saying "what if prerequiste of existence isn't either determinism but something else?"
it's like whne people are saying that, if it's not deterministic (as in, can be predicted/known in advance) then it's "random", but what is randomness? is it just not knowing in advance? not finding pattern? or is it not depending on certain factors, such as, when it comes to files, the order of the bytes, the position of said bytes, or the frequencies of said bytes, etc
if we apply something similar to reality, then we can come up with a gazillion prerequisite that can also be connected or not connected to determinism, which will likely confuse things
but to truly know the answer, I can guess instead of choosing one like "determinism" we should "exhaust" every possible theories and options until we find something that make sense
19:46
Consider: you can still make predictions about the program i = 1; while True: i += random.randint(1,6)
It's actually interesting to think about determinism in the context of a multiverse. Imagine that we're a simulation running on God's PC. God used C to program us, and somewhere made the mistake of accessing uninitialized memory - thus making our universe non-deterministic. But if we had knowledge of every program running on God's PC, then it would be deterministic.
After a hundred iterations, I can say that i is greater than zero, it's not equal to "hippopotamus", and it's likely to be closer to 300 than 600. I can't tell you what its exact value is, but maybe that's not my goal. I'm an ineffable universe-runner, after all, so my motives are cryptic.
The lesson being, determinism is a float, not a boolean?
Determinism is definitely something definite, but I can't define it definitively
That's because you're not determined enough
20:06
I've been trying to reverse engineer the Lisp code powering reality but I keep getting car and cdr confused
don't worry, I'm confused by it too. That also explain why I don't use Emacs that much these days and prefer Vim (for now) because of how python-ish vimscript looks like
20:20
Any idea how I can add link to function definition?
20:34
Nevermind, silly question
 
2 hours later…
22:58
@Kevin Hmm yes I have got the data but I'm getting some errors in my code
Even though I see nothing wrong
23:51
@Aran-Fey The block universe model is common in relativity, since the time axes of observers in relative motion are tilted relative to each other. From en.wikipedia.org/wiki/Relativity_of_simultaneity
> Events A, B, and C occur in different order depending on the motion of the observer. The white line represents a plane of simultaneity being moved from the past to the future.
Those 3 events (A, B, C) have spacelike separation, so they're outside each other's light cones, and no causal signal can travel from one to another.

« first day (4351 days earlier)      last day (819 days later) »