« first day (3687 days earlier)      last day (1262 days later) » 
01:00 - 16:0016:00 - 23:00

4:00 PM
frankly I think it's a little weird that password_hash was created at the class scope to begin with. Instance attributes are usually created in the __init__ method.
 
ah okay got it example why i thought of a return statement should be implemented
def set_password(password):
    password_hash = password

passwordhash = set_password("wwewe")

print(passwordhash)
# none
forgot about the class attribute
 
I'm guessing you're following this tutorial or something similar to it, where the setter does self.password_hash = generate_password_hash(password). This is pretty atypical behavior for a setter. Most often, it simply assigns the exact value that was passed into it. So there would be little point returning that value to the caller, because they're the ones that created it in the first place.
If you think the caller has a use for the hashed value, you could return it if you want. No harm in doing so. Just know that it's a bit unusual.
 
i received a bunch of down-votes within same time today. i believe that's has been done from specific user. is the right action is to flag one of those questions to a moderator with explaining such behavior ?
 
@αԋɱҽԃαмєяιcαη Serial downvotes are often reversed automatically. Perhaps wait a day or two, and then flag if it hasn't imprroved
 
alright. Thank you! @Kevin
 
4:07 PM
@Kevin thanks for the clarification appreciate it
 
@Kevin Wait, accepting values unchanged is a prime example of not using a setter for me.
Those cases should just be attributes.
 
Kevin.exe has stopped working
Ok, maybe so.
How about this: It's atypical to have a setter unless you're confident that the underlying data doesn't need to be accessed by the user.
In my own projects, almost all of the backing attrs of my properties have a single leading underscore indicating private-ish-ness
 
isn't there a way to address like os package dependencies in packages as well? wondering how I could deal with this stackoverflow.com/a/62105004/9044659
 
From that perspective, the reason setters don't return anything is not "because the caller already has the value", but rather "because the value would be useless to the caller"
 
@aadibajpai since practically every OS has a different package managers with different packages, that is not part of common Python package managers.
 
4:23 PM
ah, I thought I remembered reading something about binary dependencies or similar in python packages 🤔
 
@Kevin Hm, I'd say the reason is that a setter is responsible for setting a value, not for getting one.
 
Mm hmm, and I notice that the tutorial does not have a getter, which is doubly unusual
I'm still thinking about your "don't use a setter if you accept values unchanged" rule of thumb. Do you usually ensure that the original value is round-trip retrievable? i.e. obj.set_thing(x); print(obj.get_thing()) prints x's value, even if that's not what's being directly stored in the backing attribute.
I'm debating with myself whether that's worth ensuring in the average case
I suppose if you're using properties it's nice to have because doing otherwise might be quite surprising to the user
something something Liskov something
 
If it's round-tip retrievable, I use a property. If the data is modified in any way, I use setter/getter functions to indicate that
 
getter/setter for me implies that the "thing" is attribute-like, which means I can retrieve what I put in. a.b = a.b is logically a no-op.
 
Ok, we're on the same page then mostly
 
4:39 PM
Attributes that only have a getter should do the computation in the getter. Attributes which have both a getter and a setter should do the computation in the setter. The intuition being that get is more common than set.
As another intuition, "get an attribute" is just looking at something, whereas "set an attribute" means something happens.
 
Yeah.
And we know that @property-decorated setters definitely don't need to return a value because there'd be no way to retrieve it. print(a.b = x) is a syntax error, for example.
 
5:01 PM
@Kevin This perhaps makes more sense in the context of SQLAlchemy and Flask. When someone submits a web form for "create new user" you can can create an instance of User but their password will be in the form in plaintext. So, you'd have new_user = Users(username=request.form.username, email=request.form.email) and then you can call new_user.set_password(request.form.password) then commit to the db. Same for updating passwords
You could hash the password in __init__ but then you'd have to repeat the hashing procedure in more than one place. I guess it's just easier to have a single method call that handles both
 
Yeah, if you have to interface with an ORM that's picky about model class structure, then I'm willing to let some apparent weirdness slide
 
As for getting a hash, there really is no need. You're only ever going to set it or compare against it within the instance of your user
Also, if you want __init__ to run on these objects, you need to decorate it with @orm.reconstructor. I think it's ignored otherwise
^ I will have to check
Ah, no, as the name implies, that's only for recreating from the db, sorry
 
5:20 PM
@Kevin Btw, setting a default instance "attribute" as a class attribute is a pattern I see often. If not actually set on the instance, then "instance.blah" will return the class-defined default. If some other code then does "instance.blah = 'snort'", then the instance will take on its instance-specific value for blah. To modify the class-level attribute requires "Class.blah = 'blert'".
(There may be some slight memory and perf gains from this pattern, but given it obfuscatory nature, should probably be used sparingly.)
Maybe "often" is too strong - more like "here and there"
 
Mm hmm, that matches my experience
 
Perhaps "Obfuscatory Potential" would be a decent code metric, in units of "obfuts".
"What is the OP for the code you reviewed today?"
"Mmmm, about 10 obfuts."
"Oh, that's not so bad then. I've seen worse."
 
I often see this pattern by people used to Java-like classes with declared fields. It's a bit unfortunate that it seems like declaring fields but isn't.
 
1 obfut = 10 seconds of "what the heck is this doing?" time
 
5:41 PM
so 1 obfut = 6 WTF/min
 
@MisterMiyagi lol, I learn something every day. I got no clues about OOP in python and all my classes are always singletons, but I've now realized that I'm guilty of doing what PaulMcG just said. Neat that python saves me from not knowing the exact syntax
 
Hint: your classes are probably not singletons
 
I use them to implement the singleton design pattern? Or what do you mean
I mean my one instance ofc
 
I thought you were misusing the term, with "no clues about OOP"
 
let's say a little clue
 
5:43 PM
I think "I only intend to create one instance of this per program execution" is necessary but not sufficient to be a singleton
Semantics aside, I have no problem writing a class that I'm only going to instantiate once
 
I used to program like setup stuff and prepare config and db or so, then do x,y,z. Then realized that I can just push the prep into the init of an instance. The code is not that different, but it's much neater to be able to just create an object and then do whatever you want to do, without having to check if the prep is done. If the object exists, the prep is done
 
Just to be clear, does your class ensure that there's only ever one instance?
 
no, but since I'm the only one using it, my brain ensures that :)
 
I almost felt bad for assuming that you were probably doing it wrong...
 
hahaha, as said clueless. I would call a class where I only ever create 1 instance a singleton, but I might be wrong calling it that then, I guess?
 
5:49 PM
Indeed
A class where you ever create 1 instance is called "a class where I ever create 1 instance"
 
ah, wiki says the class has to restrict it
well tomato, tomato
 
and specifically "implement the singleton design pattern" is very specific
 
So if I get it right, you can't even have singletons in python, besides the pls don't construct another one, this is private _
 
@Hakaishin why not?
you just don't do it in __init__ of your class
>>> x = None
... type(x)() is x
True
None is typically a singleton. Bools are "doubleton": there's only one True and one False.
The fact that you can use x is None hinges on the fact that None is a singleton.
 
I vaguely recall that the last time we talked about singletons I suggested overriding __new__ but I was slapped with a herring so I guess that's wrong
 
5:54 PM
I see
 
@AndrasDeak well True and False are keywords now or something... gone are the days of trolling with True, False = False, True :p
 
still bool() is False and bool(1) is True
 
1041
Q: Creating a singleton in Python

theheadofabroomThis question is not for the discussion of whether or not the singleton design pattern is desirable, is an anti-pattern, or for any religious wars, but to discuss how this pattern is best implemented in Python in such a way that is most pythonic. In this instance I define 'most pythonic' to mean ...

 
it all depends on how pedantic you want to be
 
@Kevin that question should be either edited or closed...
 
5:58 PM
None is both a singleton (it's the only one of its type that can exist) and a keyword (it can't be reassigned).
True and False are keywords.
It's possible to use __new__ or metaclasses to make something most people would consider a singleton, but it's also possible to change most things in CPython (with ctypes if nothing simpler).
The real answer here is that worrying about OOP and traditional design patterns as applied to Python isn't particularly worthwhile.
 
Oct 7 at 18:34, by Aran-Fey
Noooo, don't implement singleton logic in __new__
TLDR: it might call __init__ more than once, and that might be bad
 
 
2 hours later…
7:40 PM
 
Anyone happen to know what the backslash operator does in Julia?
I'm trying to port the code here: homepages.math.uic.edu/~jan/mcs471/multinewton.pdf to Python
It's been incredibly long since I've worked with Julia, however, and I don't really understand what's going on in the function NewtonStep() function
 
@KeithMadison first google hit is on SO and relevant
It seems to do what matlab does
 
8:25 PM
So why isn't everybody using PyPy?
 
hello Because it has some limitations
 
wim
There are some good userscripts here: github.com/CertainPerformance/Stack-Exchange-Userscripts
 
8:58 PM
never heard of pypy
but it's sounds very cool
 
9:32 PM
ok i have a question: i am not detail oriented. i make a lot of mistakes (this is why i rely so heavily on comprehensive tests :D) and work on a lot of things @ a time
as a result, i often commit code that needs a few fix-ups. i don't use the code on production or stable, but i do push to other feature branches (especially since i often switch computers and things like that)
this means that i often have commit meassages that are basically "fixed a typo in [this] function" etc.
do you guys do anything different to avoid these kinds of messages (outside of becoming detail oriented :P)
 
What's wrong with those messages?
 
i've read a few articles about "--rebase" and "--fixup" but it seems like a lot of work every time i make a commit like that
nothing inherently, honestly. they just feel bad
 
you can also --amend if it makes sense to add it to the last commit
 
oh nice i didn't know about --amend
 
but that will also rewrite history
--amend --no-edit won't even ask for a new commit message
 
9:36 PM
i am ok w/ changing history in the case of like a quick typo or something
or like if i forget to stage a file
oh yeah. i think ammend is what i'm looking for
thanks :D
 
no problem
I've grown to check git status after git add that helps with not staging files, and using git commit -v when I contribute to something public that helps with committing dumb things
@KeithMadison And I answered your last question which you ignored, so I'll just move all this to a friendly place
 
9:54 PM
@KeithMadison post your question on SO itself, and tag it both
 
@smci they already asked 6 hours ago
 
@AndrasDeak Ah right
@AmagicalFishy Generally if you want to reference a lot of minor bugfixes tersely in one message, you list their issue-tracker (github/Jira/Bugzilla/whatever) numbers. e.g. "Fixed UI bugs 11111 22222 networking 33333 44444 55555". If you don't have an issue-tracker then start using one. It's always desirable to keep messages for minor commits under one 72-character line (max).
Also, you might like to identify bugs with a leading letter, e.g. 'U' for UI, 'N' for Networking, 'D' for Database etc. to make things self-explanatory, although that breaks most number-based trackers. But, pick a system that works with whatever freemium toolstack you intend to use.
 
I think it's customary to have a short message header, and then add these details on further lines below.
 
@AndrasDeak Not when that stuff is already in the issue/bug database, esp. for really minor issues, to avoid duplication. If you've ever seen messages on branch merges for 10+ issues, you don't want a combined rollup messages that's pages-long. You can generally hyperlink the issue numbers so people can one-click to the description.
 
Branches should not fix 10+ issues at a time. Change my mind.

(No, don't change my mind, I don't have the time to argue :P)
 
10:10 PM
The current single issue I'm fixing is "turns out monkeytype generated pretty useless annotations all over the place in Werkzueg, so I'm rewriting all 60 files by hand." 😭
 
> MonkeyType’s annotations are an informative first draft, to be checked and corrected by a developer.
 
Typing can be nice, but trying to type a giant old library like Werkzeug brings up so many weird corner cases.
 
+1, as advertised ;)
 
Yeah, well another maintainer signed off on it, but then I started noticing a bunch of weird stuff as I was working on other things after it was merged.
 
I imagine it's like 2to3 that fixes a lot of dumb cases, but needs inspection still
 
10:13 PM
It uses runtime information from running the tests to guess the types. It's conservative, but that results in either throwing Any all over the place or being too specific and assuming it's Union[6 different things] instead of BaseClass.
 
Ah, that's nice. Using tests I mean.
 
Also found out that until 3.9 inheriting from Generic makes instantiation ~50% slower. That's fine, I'll use a pyi file instead to add useful types for our data structures. Oh wait, mypy doesn't type check the actual code if there's a stub file, so I get none of the benefits of type checking for one of the most complex modules.
Overall I'm just really surprised typing got first-class support in the standard library so fast given the myriad ways it doesn't really hold up to real libraries.
 
@davidism your work on the pallets team is nothing short of amazing tips the proverbial hat
 
thanks :-) I need to convert that into actually making the 2.0 releases of everything. Getting really close.
 
@davidism thinking I was going to ask you a Q at some point about flask bu don't have my notepad ready... so it couldn't have been that important I guess... :p
 
10:27 PM
you can always ping me in slack when you remember ;-)
 
@davidism thanks!
might have been something re: werkzeug though... ugh... I'll worry about that later when I remember :p
 
@AndrasDeak I said "combined rollup messages" on subsequent branches. Obviously, bugfixes should each get their own individual branch. But then subsequently say 10 minor UI fix branches could be merged in one rollup branch. On large products where you need to push (and triage) multiple branches/day and have 100-1000 developer code changes, this sort of flow is essential. (Obviously it needs QA & performance suites to detect regressions and triage and back out individual changes for further triage)
 
(spinning too many plates and all that)
 
Re the following old but highly-upvoted question from 2011, asked about Python 2.x:
62
Q: Get unicode code point of a character using Python

SK9In Python API, is there a way to extract the unicode code point of a single character? Edit: In case it matters, I'm using Python 2.7.

Should it be titled "...using Python 2.x"? since many of its answers will break in 3.x Or should we leave it as is (the question body still says "using 2.7"), and just hope combined 2.x-3.x answers will appear or be revised?
 
@smci the 2.7 tag with 2.7 in the body should suffice
 
10:42 PM
@AndrasDeak No it won't, current (3.x) users searching (both SO search and Google search) will find the stale question for a decade to come. Do you think it's worth starting a separate question *"Get Unicode code point of a character... in Python 3.x"? * If no, then the existing 2.x answers will drown out the 3.x, and noone has much incentive to post 3.x answers.
 
So when you said "Or should we leave it as is (the question body still says "using 2.7")" you meant what exactly?
Don't let question mark fool you, I've lost my investment in the matter
 
@AndrasDeak "Should we a) retitle it "... in Python 2.x" (per its body and tag) or b) leave the title as is (although the body and tag still both say 2.7, and search will continue to favor it over the 3.x variant, due to the upvotes and inlinks) or c) start another sister question "...in Python 3.x"?
 
01:00 - 16:0016:00 - 23:00

« first day (3687 days earlier)      last day (1262 days later) »