#internals-and-peps
1 messages · Page 66 of 1
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
None
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
None
can someone give me some beginner tutorials for asyncio
This is #internals-and-peps #async-and-concurrency might work better for you
isn't asyncio advance ?
no not at all
what really 👀
@hexed maple Please read the channel description.
This is not a channel for getting help on topics you find advanced, it's a channel for discussing python itself
well fine
but u saying " topics you find 'advanced' " is wrong
? async is not an advanced topic, its very simple tbh
simple is relative
#async-and-concurrency is for discussing concurrent programming, including asyncio. The purpose of this channel is stated in its description.
yes and its relatively simple compared to the scope of this channel, anyway see #async-and-concurrency
i posted a link
So, I'm planning on setting up continuous deployment for a raspberry Pi from a GitHub repo. What would be the best way to accomplish this?
I've heard that I should use Webhooks, but I'm not sure if this is the best solution
Im planning on running a webserver, discord bots, and any other things I happen to develop
i use github actions and a self hosted runner, thats imo the easiest way
how does your runner work? @narrow kettle
aaaand you spammed in multiple channels
oh yeah, sorry :P
only #python-discussion and #internals-and-peps, anyway I removed it from #python-discussion
#tools-and-devops is probably the best channel
This question doesn't really relate to python which is the main thing for this channel
ok, just found this article, which is exactly what i needed. Im leaving it here in case anyone is interested: https://medium.com/better-programming/automatically-update-docker-containers-f2ccc79f4313
@unkempt rock This channel is for indepth discussion of the Python language. If you need help, please check out #❓|how-to-get-help.
:incoming_envelope: :ok_hand: applied mute to @unkempt rock until 2020-08-18 15:28 (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
What are complex functions in python? (Or is that question about maths?)
i would say splice/slice is one. as what is complex can determine on the user
or did u mean the complex function?
as well as lambda
and recursion
A complex function is a function from complex numbers to complex numbers. In other words, it is a function that has a subset of the complex numbers as a domain and the complex numbers as a codomain
That's the definition Google gives - I don't see why that wouldn't also fit with Python
Its definitely math oriented
i would say the original question is ambiguous
Yeah. In math complex refers to functions with imaginary components. Without a mathematical context it just means something with multiple parts/aspects
this is why i use the word "complicated" when i mean "complicated", and "complex" when i mean "has real and imaginary components"
the word "complex" is heavily overloaded in english anyway, depending on pronunciation
Complex is better than complicated.
it's complicated
as if i needed even more reasons to disregard the zen of python
!e ```python
def as_closing_contextmanager(cls):
def enter(self):
return self
def exit(self, *exc_info):
self.close()
enter.qualname = f'{cls.name}.{enter.qualname}'
exit.qualname = f'{cls.name}.{exit.qualname}'
cls.enter = enter
cls.exit = exit
return cls
@as_closing_contextmanager
class Thing:
def close(self):
print('Goodbye!')
thing = Thing()
with thing:
print('Entered.')
@paper echo :white_check_mark: Your eval job has completed with return code 0.
001 | Entered.
002 | Goodbye!
is this stupid or useful
hmm. maybe it just makes more sense to use contextlib.closing at call time though
its a fun parlor trick
!e ```python
class with_exit_hooks:
def init(self, hooks):
self.hooks = hooks
def call(outer_self, cls):
def enter(self):
return self
def exit(self, *exc_info):
for hookname in outer_self.hooks:
getattr(self, hookname)()
enter.qualname = f'{cls.name}.{enter.qualname}'
exit.qualname = f'{cls.name}.{exit.qualname}'
cls.enter = enter
cls.exit = exit
return cls
@with_exit_hooks(['close1', 'close2'])
class Thing:
def close1(self):
print('Goodbye!')
def close2(self):
print('Good riddance.')
thing = Thing()
with thing:
print('Entered.')
@paper echo :white_check_mark: Your eval job has completed with return code 0.
001 | Entered.
002 | Goodbye!
003 | Good riddance.
@pseudo cradle you have my permission to use it 😛 but not to blame me if it breaks...
i hate the whole thing with manually modifying qualname
i know its a simple task but i wish there was something in the stdlib for it
can I get some advice. Is this a good way to code a bubble sort ```l1 = [6,1,3,2,7,9,10,5,4,8]
def bubble(sorted_list):
for i in range(len(l1)-1):
swap = False
for i in range(len(l1)-1):
if sorted_list[i] > sorted_list[i+1]:
sorted_list[i], sorted_list[i+1] = sorted_list[i+1], sorted_list[i]
swap = True
if swap == False:
return sorted_list
return sorted_list
print(bubble(l1))```
meaning don't break out?
@feral cedar Well, it's a bubble sort, so that's unavoidable.
yeah but you can get a better O(n^2)
I'm just starting a course so i like to try and figure out the answers before I watch the video
by not checking elements that are in the right spot
oh its slow?
@fervent pulsar This is not the right channel. Please ask in a help channel or #algos-and-data-structs
okay thank you
True
class Foo(AbstractContextManager, AsyncAbstractContextManager):
close_callbacks: Sequence[Callable[[], Any]]
aclose_callbacks: Sequence[Union[Awaitable[Any], Callable[[], Awaitable[Any]]]]
def close(self):
for callback in self.close_callbacks:
callback()
async def aclose(self):
for callback in self.aclose_callbacks:
if inspect.iscoroutinefunction(callback)
await callback()
elif inspect.isawaitable(callback):
await callback
else:
callback()
# Use the default __enter__ and __aenter__ provided by AbstractContextManager and AbstractAsyncContextManager
def __exit__(self, exc_type, exc_value, traceback):
self.close()
async def __aexit__(self, exc_type, exc_value, traceback):
await self.aclose()
how about this... is this a bad idea?
the idea is that the Foo might contain some kind of data stream or other handle to a resource that needs to be closed properly
so the caller can attach one of these callbacks to the Foo instance if required
response = requests.get('https://example.net/api', stream=True)
foo = Foo()
foo.data_stream = response.iter_lines(decode_unicode=True)
foo.close_callbacks = [response.close]
with foo:
foo.do_something_important()
# response.close() needs to be called here
I know I asked about this already but did we decide that there is a decorator that returns a given value if the function raises a given error? If not I'll implement it but even then I'm not sure what I'd call it.
and then no one would find it on pypi and the problem would continue
why erru?
I mean the name of the library is important for people to be able to find it. I say this as the one making a library called bratlib
Please tell me that's a machine learning library that cooks the perfect bratwurst
nope, it's a library for reading brat files
brat stands for brat rapid annotation tool
I don't really want to make a utils.py file to implement this one decorator
huh interesting
but the other option is to make a repo for this one decorator and make it a new dependency
What is the use case? Exceptions have a different meaning from normal values
def __lt__(self, other):
with suppress(AttributeError):
return self.entity < other.entity
return NotImplemented
I have this all over the place
would rather have
@exceptreturn(AttributeError, NotImplemented)
def __lt__(self, other):
return self.entity < other.entity
Petition to add it to stdlib
I doubt they'd go for it since the cases where you want all erroneous calls to return the exact same object are rare.
except, of course, comparison operator implementations
also, regarding decorators themselves
is the function being decorated an implicit first argument for the actual decorator callable?
exceptnotimp = exceptreturn(AttributeError, NotImplemented)
@exceptnotimp
def __lt__(...):
...
this would be even more dry
think they feel the same readability wise, maybe with kwargs
def except_return(alternative, *exceptions):
def wrap(func):
def _wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except exceptions:
return alternative
return _wrap
return wrap
feels weird being three defs deep
@boreal umbra you can use a callable class instead
class except_return:
def __init__(self, alternative, *exc_types):
self.alternative = alternative
self.exceptions = exc_types
def __call__(self, fn):
@wraps(fn)
def _fn(*args, **kwargs):
try:
return fn(*args, **kwargs)
except self.exc_types:
return self.alternative
return _fn
@paper echo oh cool I'll try that
also I had my first lecture for my data science course today
are you proud of me? 
nice
looks like you have already mastered the art of yak shaving, so you'll do great 😛
python allows you to use only one CPU thread at a time right?
like multi-threading is not really a thing on python
Threads running python code will only actively be able to use one core, but you can utilize multiprocessing.
yeah
so why do we need thread.acquire() and thread.release()
if they will use only one core
ohh
ok, so they will use only one core but might function asynchronously
Because they're still threads that can switch on arbitrary instructions
like different threads might interleave
but isn't threading traditionally single core only?
doesn"t multi_threading refer to using multiple threads on only one CPU core
different threads, os threads can be seen as processes that share their memory with the parent thread, cpu threads are the actual things running in parallel which are seen as cores by the os
i see
but
in reality the processes are actually being paused and resumed on the same thread right
its not 'true parallelism' ?
idk
what is a use case for multi-threading?
people keep saying use it for I/O Bound tasks but i dont get it
Leaning bit out of topic for this channel, the CPU threads are true parallelism, so you can't actually run more than that at a point in time on the CPU. OS threads are scheduled by the OS to be executed by priority etc. since cpus are fast that can also be seen as parallel from the outside. In python however you get a lock for threads that must be acquired by threads to do most operations so usually you only have one os thread running your code.
You can use them for IO because the thread can just pause its execution while it's waiting for a resource to become available. Python also provides async coroutines which run in one thread and are managed by an event loop to run concurrently, where the event loop gets control at points you allow it to, to simplify the code flow a bit and prevent most race conditions that can come from threading
i see
i understood a bit, but not entirely
might go back and review some basic stuff about threads
@boreal umbra Attending a lecture or giving one?
@pseudo cradle attending lol
Oh, I was about to be super impressed
being a helper on this server is the closest I've come to having a teaching position
Fair enough
that being said my department was starting a Python class at one point and I demanded that they make me the instructor
they did not make me the instructor.
you're asking why @wraps(fn) is in that code? Because I didn't do that, salt rock lamp did.
though I also don't know why I do most of the things that I do.
they did not make me the instructor.
@boreal umbra politics ?🙃
what about politics?
I'm an undergraduate so from their perspective the idea of making me an instructor for anything is laughable.
well maybe u can be instructor for extra help classes
that does make sense
that being said I doubt any of the professors in my department who don't do AI or data science actually use Python, so I'm probably more qualified to teach it than the person they actually picked.
I lay awake at night worried she used camel case and for i in range(len(...)): even though they only offered the class for one semester a year and a half ago.
y dont u ask them for skill test so its fair for everyone
everything is wrong with it
I just used that and camel case as examples of shibboleths of C/Java programmers teaching Python.
Using a loop over indexes unnecessarily is definitely a sign of not knowing Python well
There are of course limited cases where you want the indices and the indices only
well, I can only think of one, but who knows what others there might be
one of my coworkers at my cafe job is pursuing a CS-like degree at another institution and he had to learn Python for one class. He said that he hated how for loops are for-each loops.
I don't really get that objection.
I think that's an "I don't use the language enough to remember its syntax" problem.
when do you use pool in mp
@raven ridge he also said that he felt like when he wrote in Python, he "didn't feel like [he] was programming"
since the language is slightly more abstract than Java, I guess.
I only say "slightly" because I can't really think of an area where Python is more abstract other than that variables are untyped
that doesn't make typing go away, it just means that you're not allocating specific amounts of memory when you create a variable. I think.
@raven ridge he also said that he felt like when he wrote in Python, he "didn't feel like [he] was programming"
@boreal umbra That's code for "it's not real programming unless it's hard to read".
I agree
Show him the internals of a major library, let him be impressed by how complicated it gets, heh
his wife is immunocompromised so I haven't seen him since like February
at one point he took a class in embedded C and told me that he didn't even have access to malloc and free
and he said that was his favorite programming that he's done
so shrug
Programming in resource constrained environments can be fun, but so is actually building novel or useful things, which is way easier in a high level language with rich libraries.
is it not the same as other languages oop?
Programming in resource constrained environments is like a videogame tbh
Beat level X with only Y this in Z time!
Programming in resource constrained environments can be fun, but so is actually building novel or useful things, which is way easier in a high level language with rich libraries.
@raven ridge wow shots fired af
novel in different ways, I think?
python object oriented paradigm is so nasty honestly
@wild harness what do you dislike about it?
I personally found emulating object orientation in C pretty fun
self
what about self
and __new__
and __init__
i mean there's nothing wrong about it, but it isn't nearly as direct as classes in C++
well, part of the point of self is that you can actually give any function to a class
i know
I mean, other than having a separate initializer and constructor, these are extremely standard in oop
i'm talking more about the syntax i guess
of how classes are defined and work
also no private variables (?)
not having private variables gives you more flexibility
not really, unless by that you mean that it lets you shoot yourself in the foot
being able to make variables private lets you have more control over the state
I think that's strawmanning the concept of flexibility
how tho ? it's exposing internals to the user
internals which you really aren't supposed to ever touch
you can already indicate which internals you don't think they should mess with. if they want to figure out what it's for and have a use case that leverages that, why not let them?
you can already indicate which internals you don't think they should mess with. if they want to figure out what it's for and have a use case that leverages that, why not let them?
@boreal umbra how do you indicate?
a leading underscore
because I think programmers should be treated as small children trying to put forks in outlets
yeah but that's weak
honestly I can see plus points for both approaches
both work pretty well
also the fact that you can define class variables from outside the class constructor in pytho
you don't have to trust people if that's not your prerogative, but I wouldn't want that baked into the language.
internals which you really aren't supposed to ever touch
@teal yacht but you might have a reason to; that's the point
you don't have to trust people if that's not your prerogative, but I wouldn't want that baked into the language.
@boreal umbra that's why you havepublic
so mark them as non-public and be done with it
@teal yacht but you might have a reason to; that's the point
@gleaming rover I'd say it's more common for that reason to be bad than not
in terms of frequency, probably.
but i also agree there is merit to both public and private which is why you should have pubic and private so if you want public you can just keep everythin gpublic
but well...it is consonant with the design philosophy of the language
mocking is much easier in Python than in any other language I've ever used - the duck typing lets you trivially substitute in a mock without needing to define an interface or subclass from the concrete type or anything, and the lack of privates means that your tests are able to patch private instance variables.
which lends itself well to screwing around with lots of fun stuff
so I'm cool with it
Like, I really don't think the whole PEP8 idea that "programmers are consenting adults, let them be" is healthy in any way, we have simple ways to prevent errors in programming for close to 0 cost, so why not use these
that's what code inspection is for
it is kind of a convention over configuration thing
@teal yacht it's not at zero cost though
but if you follow "leading underscore for non-public", you can tell @ compile time
the vast majority of languages do completely fine with encapsulation, it's p much close to 0 cost
If Python gave privates in the way that C++ or Java does, I wouldn't use it. If it allowed enforcing that a single leading underscore makes something package private and gave a warning when it was accessed by something outside the package - I could get behind that...
why would you need a warning though?
the vast majority of languages do completely fine with encapsulation, it's p much close to 0 cost
@teal yacht the vast majority of languages are not as unashamedly dynamic and free of restrictions as Python
If Python gave privates in the way that C++ or Java does, I wouldn't use it. If it allowed enforcing that a single leading underscore makes something package private and gave a warning when it was accessed by something outside the package - I could get behind that...
@raven ridge isn't that what third-party tools are for
like why do you want a runtime warning
the only case in which that would trigger when a compile-time one wouldn't is dynamic attribute access, I suppose
why would you need a warning though?
@boreal umbra to tell people who may not realize the conventions that they're operating out of contract and there are no guarantees about the behavior because of it.
sounds like unneeded overhead
I guess wanting to educate people about the convention is fair but I think it's a pretty widely-known convention
that's basically an additional check on each attribute access?
yeah - probably not worth the extra cost.
I've actually been thinking that it might be cool to have an alternative Python implementation for learning
alternative how
the only time I ever really wish I had access to private attributes in Python is when dealing with C extensions. I often want to do only the necessary part in C and do everything that could be done in Python in Python, by wrapping extension types in Python objects that help manage them. But, that often means that the extension type is fragile, and could crash the interpreter if misused - I'd be nice to have the ability to enforce more safety around that, even if that was a relatively expensive runtime check.
https://sneklang.org/ perhaps?
the only time I ever really wish I had access to private attributes in Python is when dealing with C extensions. I often want to do only the necessary part in C and do everything that could be done in Python in Python, by wrapping extension types in Python objects that help manage them. But, that often means that the extension type is fragile, and could crash the interpreter if misused - I'd be nice to have the ability to enforce more safety around that, even if that was a relatively expensive runtime check.
@raven ridge yeah, I feel the same way too
I'll take a look at that. But someone once suggested to me that cpython intentionally throttle poorly written code to penalize people who write it.
and an implementation that tells you when code could be written differently would be more ideal
"you used for i in range(len(iterable)) instead of for element in iterable when you didn't need the index"
I really hate range(len(...)) so I'd support a Python implementation that installs malware on your computer if you use it.
why not for i in ([id(obj) for obj in iterable].index(id(obj)) for obj in iterable)
patch 0.1: changed outer list to generator expression
oh no
ok thankyou
I'm sure styx already knows this, but for i, _ in enumerate(...) is better in part because not all iterables have a length, but that syntax is guaranteed to work.
uhm... I can't get you..
I'm sure styx already knows this, but
for i, _ in enumerate(...)is better in part because not all iterables have a length, but that syntax is guaranteed to work.
@boreal umbra I disagree
Tbh i just really hate how range(len( looks, but TIL
class I:
def __iter__(self):
raise TypeError
def __getitem__(self):
return 0
def __len__(self):
return 1
clearly range(len(I()) works and enumerate(I()) does not
let us agree on the former as the one true option
wow
Hold up thats illegal
I just got owned
as a wise man once said, the best kind of right is technically right
though goes __getitem__ work when the signature doesn't allow for a value?
As far as I'm concerned that's not an iterable 
oh wups I forgot my bad
How about making every Sequence in Python lazy so range(len(...)) is not viable
what is Sequence?
a Reversible Collection with __getitem__
Enforce the iterator protocol for everything 
I can't wait for python5
okay one thing I would REALLY like
Persistent data structures 👀
like
namedtuples without being namedtuples
okay, something a bit more practical
would anyone like to see Mapping destructuring?
You can have persistent DSs in python
e.g.:
>>> d = {'a': 1, 'b': 2}
>>> {a, b} = d
>>> a
1
>>> b
2
see pyrsistent
it's like one of the 2-3 things I treasure about JS over Python (syntactically)
Speaking of destructuring, were there any criticisms about implementing the __match__ protocol for PEP 622?
yes, the protocol has been removed
Oh wow
Nice
unless future changes, it won't be part of the pep
Guess I'll have to reread the spec again
hopefully they'll remove everything from the pep
It's much better without __match__
why is multiprocessing slow with more num_workers
hopefully logging will become snake case in Python 4
overhead of serialisation/deserialisation...?

import logging
logging.get_logger = logging.getLogger
@wild harness depends on a lot of things but managing more cores requires more work
I jest
@wild harness depends on a lot of things but managing more cores requires more work
@boreal umbra shouldn't multiprocessing be faster?
would anyone like to see
Mappingdestructuring?
@gleaming rover I'd be much more into this than I am into the match protocol...
@gleaming rover I'd be much more into this than I am into the match protocol...
@raven ridge RIGHT?
I would not mind mapping destructuring either
That's three people four, we can update the lang now, right
I'll leave the typo in
multiprocessing isn't guaranteed to be faster.
yes, the protocol has been removed
The protocol was very badly broken. The initial version of the PEP missed that it would be impossible to ever add__match_args__to a class that wasn't originally defined as having one, because it would be a backwards incompatible change.
but unlike JS, we don't use dicts everywhere
it's useful in web dev
the original proposal for the match protocol was that if a class Foo didn't have __match_args__, then Foo(x) would match any instance of Foo and assign it to x, but if it did have __match_args__ that would match its first argument against x
meaning you'd never be able to add __match_args__ to a library class that has been released, since you wouldn't know if they were already doing a case Foo(x) somewhere.
Ah
Would case become a new key word or what?
Interesting
Are there other soft keywords?
I'm trying to think of one but I'm tired.
async was one, but isn't anymore...
nope, it's the first introduced since the new parser
async definitely wasn't a soft keyword
it broke half the python ecosystem
Is async now a full keyword?
it started as a soft keyword and became a full keyword, right?
maybe actually, I just remember python3.5 wrecking havoc
I've never played with async but I thought they were full kehwords if you import asyncio, and are otherwise not keywords at all.
yeah, https://docs.python.org/3/whatsnew/3.6.html#new-keywords - they were soft keywords in 3.5, and became real keywords in 3.7
ah wait no you're right, now i remember telling people to downgrade to 3.5
indeed. the worst break I can remember, other than the obvious 2-to-3 one.
with discord py
we should have made a macro for this, it was asked at least 20 times a day
Now that one guy who uses async as a variable has to change that.
it was a pretty common parameter name, unfortunately... async=True to request an operation be done in a non-blocking manner.
watch code break in 5 years when typing removes all builtins
Can't they just keep it in there?
they could but they won't
Did they announce that already?
we'll see. who knows who'll be running the show in 5 years.
Not Guido
The deprecated functionality will be removed from the typing module in the first Python version released 5 years after the release of Python 3.9.0.
Interesting
Guess I'll have to be ready in five years
I use type hints a lot for anything that isn't a one off.
that one's a much easier change to make, honestly.
yeah it should be fine
async was tough because people were using it as parameter names, which means it's part of the public API.
since any parameter name can be passed by kwarg.
my first Python version was probably 2.3, plus or minus 0.1...
Wow
You belong in a python user museum
I have a vague idea of what got implemented from 3.5 onwards because of what versions my uni uses where
I learned it a bit in high school - never got too much past the writing simple games stage. Probably never anything more advanced than hangman. 🙂
came back to it much later to learn it as an actual programming language, once I had a few others under my belt.
Actually we were stuck with 3.4 for a while
Yeah, I did python as a one off a while back, then came back to it in earnest after I bullshitted my way into a python job
I think 2.6 was the latest when I started my professional python career
We might have been on 2.5 or 2.4 at work though. We're better at keeping pace in my team now :)
I never actually used python 2 professionally
I learned 3 in school and my first data science job was using 3.4 in production
wow
I started with 3.5 or 3.6, I think
I don't think I have ever used a print statement outside of legacy code
i never have either fwiw
i think i even used 3.3 in school
in hindsight it was actually very bold of my prof to start us on 3.3 and not 2.7
but also very wise
he was an excellent teacher
he drew lots of pictures on the whiteboard and encouraged students who had laptops to open idle and follow along with his lecture
i never had any confusion about scoping or lists or mutation like a lot of beginners who ask questions here seem to, he did a great job teaching us the language
if i monkey patch a class with a new method, is it possible to also patch the class's annotations to reflect the new method?
wait.. classes dont even have __annotations__
how does that even work?
class Thing:
x: int
y: float
where do these annotations get stored, and how do you access/modify them?
ah, __annotations__ only gets created if the class actually has annotations, otherwise the attribute is missing entirely
but functions arent included in that
so seems like there's no additional patching required
functions have their own __annotations__, i assume same for methods
methods are functions in a class wrapped into MethodType, so yeah
Hi all, I just wanted to share a project that I am working on; https://github.com/mmajewsk/Tonic
@mortal hare use machine learning to teach it about your house and bring you beer
might not have enough data in a lifetime to do that
It delivers beer to a location within a 10 mile radius of you with 75% accuracy
"fetch me a beer"
robot: leaves house and travels 9 miles east
If you have an if True: will cpython optimize that away
What if you have an if False:
Either one
That’s a pretty trivial optimization that most other Lang’s will do
Does cpython do it
It does optimize it away
>>> def func():
... if True:
... print('yes')
... if False:
... print('no')
... else:
... print('maybe')
...
>>> dis(func)
3 0 LOAD_GLOBAL 0 (print)
2 LOAD_CONST 1 ('yes')
4 CALL_FUNCTION 1
6 POP_TOP
7 8 LOAD_GLOBAL 0 (print)
10 LOAD_CONST 2 ('maybe')
12 CALL_FUNCTION 1
14 POP_TOP
16 LOAD_CONST 0 (None)
18 RETURN_VALUE```
Gotcha, i figured it would
same goes for other literals
and expressions that can be pre-calculated, like 10 % 2
@mortal hare use machine learning to teach it about your house and bring you beer
@unkempt rock It already can do that
but without ml
although storing them in a name removes the optimization immediately
>>> def func():
... x = 10 # Advanced stuff, can't take guesses anymore
... if x:
... print('yes')
...
>>> dis(func)
2 0 LOAD_CONST 1 (10)
2 STORE_FAST 0 (x)
3 4 LOAD_FAST 0 (x)
6 POP_JUMP_IF_FALSE 16
4 8 LOAD_GLOBAL 0 (print)
10 LOAD_CONST 2 ('yes')
12 CALL_FUNCTION 1
14 POP_TOP
>> 16 LOAD_CONST 0 (None)
18 RETURN_VALUE```
Could anyone help me out? im trying to make a menu but struggling a bit with userinput
Ok thanks
Could anyone help me out? im trying to make a menu but struggling a bit with userinput
@idle isle Did you get it?
Does anyone know what the code for this would need to be??
Implement a function that accepts an string of 10 integers.
Have the function return those numbers as a String in the form of a phone number.
Use the following format for the phone number:
(XXX) XXX-XXXX
this isn't a help channel, check out #❓|how-to-get-help
when using classes as decorators, do you use camel case or snake case?
still pascal case
any particular reasoning
looks better, probably
you would usually instantiate the class before using it as a decorator anyway
I'm using __init__ for parametrisation
It's still a class, I prefer to use case for denoting the implementation, not the use
the standard library uses snake case for decorators that are classes.
wait, that one actually is a function... let me find a different example...
ah, https://docs.python.org/3/library/functools.html#functools.partial is the one I was thinking of.
a lot of the stdlib has the wrong naming convention
A lot of the stdlib used to be 3rd party libs, and remained their own style when they joined the stdlib instead of turning everything into pep8.
int, dict, str, etc are all lowercase, too.
map, range, enumerate etc are also types
because they "act like" functions
@paper echo This is what I go with, too. If it acts like a function, and is meant to be used like a function, but happens to be implemented as a class, I use snake case.
implementation details shouldn't drive the name 🙂
the purpose of the naming conventions is to help readers understand the code better, and calling it Enumerate instead of enumerate wouldn't help with that.
@paper echo This is what I go with, too. If it acts like a function, and is meant to be used like a function, but happens to be implemented as a class, I use snake case.
@raven ridge this was my thought process
It's still a class, I prefer to use case for denoting the implementation, not the use
@teal yacht I feel differently
like imagine you originally implemented your decorator with a function and now you want to use a class; would you rename it just for that reason?
breaking your public interface in the process.
^
it utilizes CapitalizedWords, which is a name I've never heard anywhere else
upper camel case for classes, I suppose
Oh, huh
Wiki apparently calls it "Pascal Case"
and which people usually consider a special case of camel case.
and "dromedary case" (which is pretty amusing) for lower camel case
Is that just for classes? I could have sworn that all things like funcs/methods/vars were all snake
yes
k
upper camel case classes, upper snake case "constants" and lower snake case everything else
oh, lower camel case for logging 🙂
eh, lower came case for a handful of legacy libraries, against everything pep-8 says. 🙂
important to note that it's mostly because pep8 didn't exist back then
pep8 does say "disclaimer: use camelcase for legacy reasons"
mostly <-> entirely ?
and logging was based off some Java library, I believe
log4j
some things were absorbed into the standard library after starting their lives as non-pep-8 libraries that became big and influential, I believe - so in those cases backwards compatibility for the non-compliant names was the reason.
The only problem with naming I have is datetime with the shared module and class name, otherwise not following the guide is just... meh
that one's a constant source of confusion.
the lack of word separators is mildly irksome IMO
but still better than camel case
not sure why it irritates me so much in Python
module 'datetime' has no attribute 'today'
...
type object 'datetime.datetime' has no attribute 'datetime'
☹️
not only is datetime.datetime confusing, but datetime.datetime.now is a classmethod and not a top-level function
datetime.DateTime would solve all this
Would like to see that changed, but guess that's not happening anytime soon
why change it? just create an alias
in datetime.py:
DateTime = datetime
it's that easy
the core of programming is making tedious things simple, and easy things hard.
and easy things hard.
like we were saying...why write code that solves a problem you have now when you can try to write code that may solve a problem some time down the road? 🙂
there's a term called "the pit of success". The idea behind it is that too many people design libraries where using them correctly is like climbing a hill - they put lots of obstacles in the way of doing things the right way. Instead you should design things in a way where people fall into doing things the right way accidentally, because it's less friction than doing it wrong.
related to the principle of least surprise
i like that
surprisingly, only managed to find this issue on the matter https://bugs.python.org/issue5530
the str vs unicode handling in Python 2 was the worst example of making it easy to do the wrong thing. Any byte string could be coerced to a Unicode string, and it would work fine as long as it contained only ASCII bytes. Any Unicode string could be coerced to a byte string, and it would work fine as long as it contained only ASCII codepoints.
in practice this made it very easy to write code that works on your machine with your test data, and fails on someone elses, or as soon as someone runs your code with a real person's name, or any sort of user supplied input.
Please don't do this. We need stable APIs. Trying to switch the entire
community to use CapWord APIs for something as commonly used as datetime
sounds like wasting a lot of cycles with no reason except the mythical
"PEP 8 conformance". As I said, it's a pity we didn't change this at the
3.0 point, but I think going forward we should try to be more committed
to slow change. Additions of new functionality are of course fine. But
renamings (even if the old names remain available) are just noise.
all the more it should be switched if it's commonly used
maybe without a BDFL at the helm we can actually have community input...
indeed @gleaming rover
datetime.datetime 🤔
i guess someone could write a PEP for it
although honestly I'm fine with now being a classmethod
Where is that quote from
wait, is it?
@swift imp from the rejected patch that numerlor linked
yeah it is to access the constructor I guess
What's the big deal
so now i have 2 peps i want to see that dont exist yet: function composition with @ and adding CapWords aliases to datetime and time
yeah datetime.datetime irks me
do we really need a datetime and a time, incidentally?
Well
@gleaming rover time has things like sleep and perf_counter so yeah i'd say so
time has stuff like time.sleep
like separate libraries
i'd love a function composition operator but i doubt it'll ever get into the language
^
Yes those should remain separate
@teal yacht
def compose(f, g):
def _fg(*args, **kwargs):
return f(g(*args, **kwargs))
imagine if you could write f @ g for this
not sure about the way they're separated but yeah that's reasonable
Why can't you just do func1(func2)?
but what if you have a callable matrix?
@gleaming rover well a class can only have one implementation of __matmul__
precisely
and __matmul__ beats __rmatmul__
rip numpy
I wrote a small wrapper that defines @ so you can decorate functions but it's dumb
so, f @ callable_matrix is function composition
and callable_matrix @ f is matrix multiplication
__matmul__ is the biggest meme of a builtin
i mean its pretty nice if you are a numpy user
it's the middleground between adding and not adding numpy to the stdlib
You know how rare matrix multiplication is?
with numpy it's not
so,
f @ callable_matrixis function composition
@paper echo but what if I want the reverse order?
No even in numpy it's pretty rare
it's really not
I'd say it depends on what you do
@gleaming rover tough, because that's how __matmul__ and __rmatmul__ work
what if you have conflicting implementations of +? same thing
@gleaming rover tough, because that's how
__matmul__and__rmatmul__work
@paper echo PEP denied 😢
Most people doing ML or DL arnt implementing their own algorithms
https://www.python.org/dev/peps/pep-0465/ they have a table on statistics
They're using scipy and sklearn
I would like it if we had more operators
@gleaming rover this has nothing to do with @ and everything to do with how operators work in general
And just calling methods/functions
it's more common than |, << , -= etc
@gleaming rover its inherently asymmetric by design
yeah, I know
I was kind of kidding about callable matrices
but still...
are there any free symbols left?
! and $ aren't used, right
They should have just implemented .*
@swift imp I'm implementing my own algorithms in addition to using those
I mean, operators don't have to be one character
#!
.* works in matlab
! shouldnt be used, its negation..
@unkempt rock in other languages...
@swift imp dont forget that python is also used in academia quite a lot now
not just ds/ml industry
a lot of people using numpy in a lot of fields
yeah, .* in matlab is * in numpy
not really a reason not to use it IMO
the ` and <> operators were removed from Python.
I'm saying * is wrong too
so that's two more that could be added back 😄
@gleaming rover Yes, but python shouldnt be confusing
@unkempt rock why would it be confusing?
What do you mean there's no callable method *
if you're coming from another language you know that syntax differs between languages
so are and and or confusing?
because most languages use & and |?
Heh or C
is and == is another bad decision imo
most use && and ||
&& and ||
I mean, sure, but numpy was built in python, there's no way around it @swift imp
beat me to it
which does make & and | confusing, honestly.
and element wise multiplication is extremely common
& and | are bitwise, right
Well, in C & is an address operand
and && and || are logical
&& vs & and || vs | isn't easy to explain to people.
@gm yes
so making * matmul and having element wise mul as a method would have been a mistake
Well, in C & is an address operand
@pseudo cradle and bitwise arithmetic.
so making
*matmul and having element wise mul as a method would have been a mistake
@teal yacht agree
Ah, right
I think the biggest issue is that there arnt even matrix objects
matmul as a dunder confused me
What? @gleaming rover !=?
not using it but it's existence
we don't really need a matrix object
I don't see why matrix multiplication couldn't have just been a method
the rationale is explained in the pep, it's comfy
methods don't generalize to arbitrary types.
it looks nicer in chains of expressions
It's not communititive anyway
not every operator is commutative, that's not an argument
the entire advantage of custom operators - the only reason for operators over methods beyond syntactic sugar - is that they can work on arbitrary pairs of types that don't have prior knowledge of each other.
that's something you can't do with methods.
It's just such a rare operation and also no communtative that I don't see why it couldn't be a method instead of a Dunder
honestly this matrix multiplication debacle
could have been solved by defining matrix multiplication as the Hadamard product instead of what we have now
🤔
Dot with circle?
but * is already the hadamard product
Yeah hadamard is element wise
changing that would have broken every existing numpy code
I'm kidding
and hadamard product is vastly more common than matmul
hence the 🤔
ah, wasn't obvious to me, mb i guess
I should probably have used some other emoji
sarcasm is so hard to convey
but anyway yes, I agree
elementwise operations are far more common
IME @ least
no, no, they are
you know one nice thing about Scala
They are...
it allows you to define arbitrary operators
you end up with some kind of symbol soup
op stdlib scikit-learn nipy combined
==== ====== ============ ==== ========
= 2969 5536 4932 3376 / 10,000 SLOC
- 218 444 496 261
+ 224 201 348 231
== 177 248 334 196
* 156 284 465 192
% 121 114 107 119
** 59 111 118 68
!= 40 56 74 44
/ 18 121 183 41
> 29 70 110 39
+= 34 61 67 39
< 32 62 76 38
>= 19 17 17 18
<= 18 27 12 18
dot ***** 0 ********** 99 ** 74 ****** 16```
Delicious
Eh, ARB operators seems bad idea
smybol soup
Looks like a rocket ship
it puts a bar to entry in the language, which is not something wanted by the python community as a whole
that's one of the reason people are scared of haskell
because many common operations are operators, so you have no way to know what they do at first glance
that's one of the reason people are scared of haskell
@teal yacht I can't imagine why
after all, a monad is just a monoid in the category of endofunctors
🙂
memes aside, I think it's not a problem if we ignore beginners
it doesn't help that many people who say "Haskell is easy" tend to unload a ton of category theory on you
You mean you don't like a language that's based on a field of mathematics that like 99% of the human population never learns? That even a lot of math majors don't learn?
these are the worst
I think every field will have people who are like "X is so easy"
Because they learned it
any explanation that begins with "let us assume" or "given that" has instantly shut out a ton of people
No man category theory is freaking abstract even for a mathematician
But tbh, a huge majority of people that I've noticed say "haskell is too hard" tried it for 1h or were just put off by the syntax being different
yeah
I mean
it's hard to convince some people to use map/filter (or comprehensions) already
functional paradigm is great but
yay for CS education being textbook java oop
I guess since I didn't come from a CS background
I don't really have preconceptions in that regard
I don't get this "just make it a method" line of argument. + needs to be an operator; we cannot have an add method because we need radd as well, and we need a way to signal to the interpreter that it may need to try both.
I personally don't like map/filter
what is the use of \r
in file handling
I mean, there's such thing as something having a steep learning curve or a high barrier to entry, even if it evens out after that
depends, what OS are you on
I personally don't like map/filter
@swift imp the ideas?
pls help me
Labrador <: Dog <: Animal <: Living amirite
like in Python I generally avoid map/filter because I prefer comprehensions
Same reason as Guido
@unkempt rock #❓|how-to-get-help
but the concept is nice
Comps are clearer
@unkempt rock think you wanna post that in a help channel
ok
I want multiple dispatching
like Julia?
imo the reason map and filter are yucky in python is largely because lambdas are yucky
and also because typically you need to call list() at the end or something
which sometimes is great and other times isnt great
i've done things like
def lmap(fn, *iterables):
return list(map(fn, *iterables))
and id probably be happy to import a library full of functions like this
from itertools import chain
def lmap(fn, *iterables):
return list(map(fn, *iterables))
def lfilter(fn, x):
return list(filter(fn, x))
def lflatten(fn, x):
return list(chain.from_iterable(x))
etc.
doesn't seem too unreasonable
Yeah, generally, you would unpack it, but in many cases you would not. Besides, you don't want map() accidentally constructing a huge list. Also, some people might not need the entire result of map(), just some of its elements on front; while this can be better achieved with generating a full list, you can still do it fine with iterators.
hi huys my name is pranay and i am new to git and git hub , and i am confused that what is snapshots , can anyone explain me?
@wide thistle This channel is for indepth discussion of the Python language. If you need help, please refer to #❓|how-to-get-help.
so... I'm doing this refactor and I THINK I just came across someone using bare exceptions as control statements in a for loop and wanted a second set of eyes just to
a) see this insanity that I had never even thought of, and
b) ensure that is indeed what it is before I potentially rip out a bunch of needed exceptions
for band in sorted(self.key()):
try:
full = np.vstack((full, self.dct[band]))
except:
full = np.array(self.dct[band])
I have a few things to say about it, but I'm busy, but you can except NameError if that's what you meant
no, like, i think it is using try/except instead of if/else
full is undefined to clarify
so it would be defined within the except
and then it would loop back up to the try statement to finish out the vstack
I think is what this does
There are a few cases where using a try/except can be valid for normal control flow, but none of those cases include using a bare except with no type specification, I think.
tbh I had never heard of try/except as a control flow
part of why this looks so crazy to me
look up eafp vs lbyl
@safe linden Because the except has no type specification, it's hard to know for sure what it's supposed to do.
Most likely it's only looking to catch one particular exception.
But the person who wrote it was too lazy to add it.
as in
if s.isnumeric():
x = int(s)
else:
x = 0```vs```py
try:
x = int(s)
except ValueError:
x = 0```
@safe linden But yeah, that's pretty ugly.
I guess my confusion is, even if x = int(s) works, if there was a pre existing uncaught value error, couldn't that lead to some crazy runtime fun?
There are various ways you could write that code to be more intuitive.
my plan is to just replace this with if else logic
I think there are a lot of other places this has been done too because I've been filling in bare excepts for a few thousand lines now and it just clicked for me what these are
for i, band in enumerate(sorted(self.key())):
if i == 0:
full = np.array(self.dct[band])
else:
full = np.vstack((full, self.dct[band]))
This feels like a big improvement to me.
Because you can see clearly what the intention is.
yeah, I'm thinking going that route
oh and the other thing i wanted to say
do not use vstack like this, it's awful in terms of performance
@teal yacht I meant in the example you posted, wouldn't any ValueError exception that has been thrown potentially reassign x?
use a python list, and cast to np.array at the end
even if your try worked as intended?
yes it would, hence why it's important to throw sensible errors
there's also finally: to avoid that issue
try:
x = int(s)
except ValueError:
x = 0
finally:
somecodethatmaythrowvalueerror()
print(x * 2)```
@safe linden The contents of the try block only contains an int() call, though.
There's pretty much only one possible way ValueError gets thrown.
yeah, I was trying to understand this in the idea of if it existed as a snippet of a larger function
>>> t(t1, setup=setup, number=100)
8.820794968996779
>>> t(t2, setup=setup, number=100)
0.016266275008092634```vstack vs list.append
setup = """import numpy as np
x = np.random.randint(100, size=(100, 100))"""
t1 = """
for i in x:
try:
y = np.vstack([y, i])
except NameError:
y = np.array(i)"""
t2 = """
y = []
for i in x:
y.append(i)
y = np.array(y)"""
from timeit import timeit as t```
This is what I mean by try/except being valid for normal control flow only in certain special cases.
Like when you wrap an int() call and nothing else in it.
I mean, it is certainly very unique and with clever throws could probably lead to some interesting code behavior
whether interesting is what is intended however...
You also generally don't want to be clever. With the int() example, it's still very obvious what's happening.
Unlike in your original example.
I'm sorry my ocd is kicking in, but please acknowledge my comment on np.vstack vs list.append
yeah, it's honestly been a trip. I'm just a student but I'm pretty much doing software architecture and development for a lab and it has been fascinating learning how little I know
your comment is acknowledged, though tbh I haven't really processed it XD
trying to show alternatives to vstack?
@safe linden That sounds like good experience.
Most people don't get to practice taking charge of software design for a real project so early.
showing that you shouldn't use vstack in this example really
it's about 800x slower on the machine i benchmarked it for a small 100x100 array
Yeah, it's been really crazy because I thought I wrote good lines that were readable and didn't throw error and that's what programming was
I am realizing very quickly that is the least significant part
Well, it's not unimportant to write readable code...
as I try and take a code base written by 6 different people across a decade and turn it into something with extensibility in mind
oh, i meant that say a given line or file would be readable
but the package would have no structure to it
just whatever I cludged together at the time
Well, sure, there are other important aspects as well.
and I am also learning what I thought was readable was not nearly as good as could be
like my mind was blown at the idea of indenting before operators rather than after
like it seems simple, but the literary convention is after so I always did that
That's generally how I prefer it, but opinions differ on that.
but when I started doing it before, it reads like a balance sheet and is beautiful
An advantage of indenting after operators is that you can get for example boolean expressions to line up better.
also didn't mean to ignore you Lgneous, that is a fascinating point
if (x == y and
a == b and
f == g):
interesting
thoughts on indenting after for boolean expressions but before for arithematic ones?
But if a given clause is long, it might be harder to see what the operator actually is if it's at the end
or is that just inconsistent
So I tend to prefer indenting before the operator
I think I usually stick to one for all operators, but I'm not dogmatic about it
At work we allow both
very fair
also, curious for your thoughts. I've been basing a lot of the style I'm trying to use on PEP 8
it seems like it is mostly good ideas though I don't really have enough experience to recognize any bad ones
We use flake8 to lint our code, we basically follow PEP8 with a few exceptions where we feel like it's too restrictive to be convenient.
where do you feel it is too restrictive? line length?
Well, what we just talked about is one thing. PEP8 states line breaks should go before the operator, but we don't want to enforce that.
And line length, yes.
PEP8 says 79 characters, which I think is pretty silly these days.
So we go with 119.
oh interesting, I saw them talk about 99, curious why 119, and also if there is a reason these go in intervals of 20
Because monitors are big these days, and 119 fits easily.
I don't think there's any 20-interval standard. I haven't really heard of anyone using 99 either.
It was 120 at my last job too.
hmm, I may have simply mis remembered the PEP 8 documentation
PEP8 says 79, anyway.
I prefer a shorter line length (80-90) because for me it's simply hard to read lines that span my entire monitor, especially if I have two files open side by side
oh, I had it right, they recommend extending to 99 if you do extend it. But it sounds like there is no particular rhyme or reason to any of it past what works
99/100 is pretty common; I find 120 a bit too long for logic but things like strings really can use longer limits
I tend to prefer longer identifiers, that might be part of it.
I really hate cryptic abbreviated identifiers.
there certainly is a benefit to be had with nice full words
But avoiding them will increase the average line lenght somewhat.
what's not clear in PMOVSXBW or wcsxfrm
well thanks again, I think I should get back to the grindstone
oh
so there is a bunch of random commented out lines of code that still lingers
I think maybe from before the project used git
Recommendations on just ripping it out or putting it somewhere?
@safe linden Getting rid of those as soon as possible is a good principle, I think.
Save one state of the current code with them as is
If you're using git, then great. Then add a commit that gets rid of it all
They get increasingly outdated and less valuable as time goes on. If you really want to keep it for later, create a branch for it or something.
If it is working as it is right now, those lines are probably useless now
the original package will exist as is, with all this in it. I'm creating an entirely new distro from the old code
Though I think if you need to do that, in 99% of cases you will just forget about it and never use it.
Ahh
If it is an half implemented feature, maybe you should move them to a new branch and comment them out?
Then you'll probably not need them at all
A lot of linters I've used have a warning to remove commented out code.
Now if only someone taught me how to use git.. :(
I can see that. it honestly feels a little unecessary with correct git usage
you and me both Darr XD
@visual shadow Git gud. 😄
😆
omg, I'm stealing that
Speaking of git, is there some 'meta-git' tool that tracks changes in the git history? Because I can screw up my local git history, right?
I guess you could make a git out of the git history 😂
@grave jolt Not really. Nothing builtin anyway.
if you are pushing to a remote branch, wouldn't that sort of do it?
You can recover some changes from the reflog, but it's temporary.
I'm not entirely sure what that would do to one's sanity
or do I completely misunderstand the question
I think the latter. Basically you can falsify git history by using rebase or something along those lines.
You can rewrite the git history with certain commands.
I forget, since i never use git much. (and I know I should. I really do)
Such as rebase and amending commits.
Darr, what really did it for me was using an editor with strong git integration if that helps
though I don't really know it tbh
but it is helping
I guess what @grave jolt wants is a way to have a record of history rewrites.
yes
That sounds like the path to madness to me though.
Regular git histories are already complex enough.
It does. I felt like I was closest to learning git when that happened. My issue is, we have a crazy amount of tape around what softwares we can use, and we keep switching permissions on a per project basis
Probably better to just learn to use good principles when managing your branches.
I mean, hypothetically, all of this stuff exists in files that could be versioned...with git...
If you just never use history-rewriting commands, you can't really lose anything.
For some reason, each ide that integrates nicely with git and git itself is not on our pre-approved list yet.
I guess the best possible principle is not rewriting history at all 🙂
It's such a hassle to try getting the permissions cleared that we end up just doing work without version control
wait, vscode isn't approved where you work?
@safe linden History rewrites are destructive. You can lose information permanently that way.
(cue 15 copies of the same file with v1-15 added at the end)
@grave jolt I would say that you should avoid it except for well-established and well-understood workflows.
Sort of. It's approved in our local environment, but each project we work on a new Vdi
So.. Yeah... Sigh.
Amending a local commit is pretty safe, because you're only changing the previous commit.
Interactive rebasing a local branch that you haven't pushed is also quite difficult to mess up, and can be very useful.
It's when you are rewriting a branch that someone else is accessing or writing to that things can get really hairy.
So like, never ever do it to a mainline branch.
man I'm curious to see what the approved tools list looks like
probably emacs
generally emacs is not allowed in those restraint environments
packages are super common and could be malicious
@visual shadow
It's such a hassle to try getting the permissions cleared that we end up just doing work without version control
Yeppp. Rip
sorry, meant emacs as a cheap stab at humor
ngl I'd quit if I ended up in a workplace without vc
That would definitely be a dealbreaker, yes.
you could probably tell management that this is increasing project timelines drastically...
I mean, my current workplace is not great, but at least we're not on that level.
yeah well I don't find it very humorous 
I think we are drifting into off-topic
Ah you're right, my bad
I kind of forgot what channel this was for a second there.
I didn't even realise it 😅
I'm the big bad moderator now
Can't run a discord of a few thousand without some of those
Are informational PEP like things mostly a python thing? I don't remember such clear style conventions when I was in the depths of C++
I don't think every language has a single widely adopted standardized style convention.
But some probably do.
Some have multiple competing ones.
I believe so actually, or well, it's more formalized and well advertised. Other languages has like mailing lists that never come out for wider consumption
Or if they do come out, they're pushed to websites that have such horrid layouts it's really difficult to read.
Also this may verge on off topic but it is pep related. Should I stop pushing for every person I know who is learning python for the first time to read the PEP 8 documentation?
Cause I feel like I am part of a cult a little bit at times tbh
Ease them into it perhaps, as opposed to pushing it from day 1
Let the question of code style come up organically.
I think styles and other opinionated things are one of the few areas where arguments of authority are good
I'd rather say "we'll use pep because the big bois said so", than having 340982304823 conventions in place
What I personally suggest is letting them code for 6 months in peace, and then turning on their code style analysis in their editor secretly one day. Watch them squirm as the entire file gets highlighted. Every single line.
see the state of C
@safe linden Everyone should learn to follow style conventions eventually. But it's good teaching practice not to overwhelm your students with too much information all at once.
People pick it up pretty quick after that in my limited experience
I guess my issue is I know the uni I am at will never touch on programming as an employable skill. It uses it as a tool to illustrate CS concepts
so things like style aren't even mentioned
like the people I talk to aren't aware style is a thing, so the conversation won't come up organically
similarly, versioning and architecture also get the boot
You could certainly introduce the concepts to your peers if you get the chance
Even if you don't force them to follow it religiously
Tough to say. There's some merit to actually experiencing the problems that show up if you don't follow code styles, but honestly we usually pick these things up on the job. If you try to teach things that people don't see a use for, it may be tough to get the message across. Gentle nudges at most.
just silently add a github action that rejects non flake8 compliant code
Worse case scenario, you'll get a rude awakening when you actually start working, but it's nice to be familiar with these things ahead of time.
Probably makes a better impression in technical interviews too.
Thats a very good point honestly, didn't even think of that angle
@teal yacht That's not a bad idea at all.
That's valid. I didn't appreciate the significance of most of this until doing a refactor. It's been interesting because at a university, you have a lot of self taught programmers who have never been in industry
In the industry too honestly, the same statement applies when you start
By interesting, I guess you mean horrible.
so a lot of the wisdom you all just kind of know hasn't crossed over, it's been one of the biggest benefits of being on this discord just to get bits of that insight
@safe linden I know, I went to uni once too.
Some of the information filtered through the student community as time went on, though.
Like, some people learned stuff on their own and taught others.
Even if we never had classes on all of it.
Yeah, I am certainly getting that vibe. And am trying to bring some of that light back to the cave. But I don't know enough to ensure I'm bringing back good ideas XD
Thus why I love the PEPs
cause python went and really tried to put a lot of the good ideas in one clearly labelled place
As long as you can convey uncertainty when you're actually uncertain, I think you'll only be doing good.
Sometimes the trick is to just start the discussion, people are quite capable of figuring things out if you can just reveal what we don't know, you know?
hmmm. interesting. I'll think on that. That organic approach you both were recomending.
Thanks again to all of you. I swear I learn an entire masterclass of information every time I come to this discord.
Good luck
I've lived with linters on my projects. I've turned them off. It's not a good idea imo. A warning in PRs is fine but to fail builds on a missing newline is obnoxious and stupid imo.
It's easy to prevent letting a missing newline get to the CI with the right tooling.
And I much prefer spending some extra time cleaning up my PRs than having to read code that's all over the place.
imo having to fix erroneous typehints and styling that someone introduced in the file you're editing is worse
that's why you accompany the linter of a formatter

that way actual convention mistakes do not pass, while simpler formatting ones get fixed
Does the linter check unit tests?
You mean if you usually apply the linter to test code?
The most recent unit tests I've written use a lot of mocks so those obviously won't be the right type
That'd be nice to have a linter/tool to test the quality of a test
@undone hare Mutation testing kind of does that. A tool randomly modifies a piece of production code under test and then checks if that causes any test to fail. If not, it tells you what the change was, so you can add a test to cover it.
Code coverage is good, but mutation testing goes deeper.
yeah i didn't mean "too" as in it does the same thing, i meant that's another tool to use
Sure
Ah that's interesting
@boreal umbra I'm not sure about various type checkers like mypy but if you specify the spec for your unittest.mock.Mock instance, it will correctly pretend to be of the specified type, e.g.:
>>> from unittest.mock import Mock
>>>
>>> isinstance(Mock(), int) # Without a 'spec'
False
>>> isinstance(Mock(int), int) # This pretends to be an int
True
@sacred tinsel I'll have to look into that. I used simple namespace for the most recent test.
The first library I wrote tests for was already written by someone else, so nothing needed to be mocked.
It is the thing that when you google "Python dict using attribute" you never find even if that's exactly it
I mean, you do lose every other dict functionalities
Well yes
It's a very nice utility so you don't have to do class Name(object): pass just for attributes, but it's not really a proper attr dict if you need anything else from it
I've had someone ask me how
a, b = b, a
works internally. Turns out, if you do dis.dis and get the bytecode, it pushes a and b to a stack, and rotates it
oh dear
hmm, that's actually not what I'd expect, must be a specific optimization
I'd expect it to evaluate the right part (a tuple of values) and then do deconstructive assignment to the values in the left part.
CPython optimizes that away when you swap two names around, yeah
yeah i thought it would do that too, since there's only one assignment at a time
@gloomy rain and @undone hare talking about mutation testing, I'm the author or mutmut :)
@half wolf You presented at PyCon Sweden, right?
Yes I did!
Glad to hear. I had to go for a pretty basic talk given most people don't know anything about it.
I played around a bit with Cosmic Ray earlier, so I was somewhat familiar with the concept at least
Hopefully after it didn't require rabbitmq to even run :)
I couldn't even install it when I first tried it heh. My public shaming has made it tolerable (imo barely).
I seem to have some faint memory of it being quite a hassle.
you know that feeling when
everything in python has nice and cozy snake_case names
and there is just logging library
@oblique raven I take it by changing the nameservers from Namecheap's default to Cloudflare's also the ability to redirect any traffic to my website gets disabled, correct?
A lot of the options that namecheap provide are disabled when you use cloudflare
But
You can also do most of the same things, and more using cloudflare
Is what I said though true?
I believe so
So I know there's some back and forth between camelCase and snake_case.. but what if we COMBINED THEM.
A variable named, for instance, heartRate_BPM
Interesting or a sin?
or is heart_rate_bpm better
the latter
as a matter of being in a consistent style.
also, imagine if you have a class named heartRateBpm
although in languages like Java acronyms shouldn't be in all caps, according to PEP8 the correct version would be heartRateBPM
what about inverse camel case
when the first letter is small and the rest are capitalized
lIKEtHIS
or maybe just the last letter of each word is capitalized
likEthiS
I remember that I put that in the spec of my imaginary language https://gist.github.com/decorator-factory/067932affa54488627d7913be11a4e2a
It has so many wonderful ideas, like an integer type that cannot take a value from 1 to 71
hah
you know that feeling when
everything in python has nice and cozy snake_case names
and there is justlogginglibrary
@cloud crypt someone summoned me?
Hello! My computer vision program, it finds a face and puts a box around it, how could I make it so when a face is detected it runs a code?
so if I am reading PEP 8 correctly, it says function names should be lower_case and also file names should be lower_case?
I feel like I have to be wrong since it is already leading to some imports that look unclear
though the alternatives of UPPER_CASE and MixedCase would also cause problems
i was working with tkinter trying to make a GUI that could automate making directories and open my IDE pycharm. I kept using the .destroy() function to close the window after it opened pycharm. it would just keep saying not responding, so i used the command line and did
os.system('taskkill /f /IM python.exe')
which will force quit the application. Now I can't open python applications anymore. Like i can't double click them. They all force close instantly. I've tried to repair it from control panel in programs, i've shut down my pc and rebooted. I've shut down all command processes in case something is still running, but nothing works. And now i can't use any of the python programs i made on my computer without manually running them through pycharm or through the command prompt.
so if I am reading PEP 8 correctly, it says function names should be lower_case and also file names should be lower_case?
@safe linden why do you find that problematic?
i was working with tkinter trying to make a GUI that could automate making directories and open my IDE pycharm. I kept using the .destroy() function to close the window after it opened pycharm. it would just keep saying not responding, so i used the command line and did
os.system('taskkill /f /IM python.exe')
which will force quit the application. Now I can't open python applications anymore. Like i can't double click them. They all force close instantly. I've tried to repair it from control panel in programs, i've shut down my pc and rebooted. I've shut down all command processes in case something is still running, but nothing works. And now i can't use any of the python programs i made on my computer without manually running them through pycharm or through the command prompt.
@unkempt rock try a help channel #❓|how-to-get-help
ok i did
from PEP8
"Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability."
"Function names should be lowercase, with words separated by underscores as necessary to improve readability."
I am reading that as the naming conventions for functions and modules are identical with functions preferred as longer and more descriptive?

