#internals-and-peps

1 messages · Page 81 of 1

wide shuttle
#

We've taken moderative action.

unkempt rock
#

Lol

peak spoke
#

What are your thoughts on sticking all imports needed only for typing under the if TYPE_CHECKING condition after postponed evaluation of annotations rolls around?
I've worked with a few libs now where only some utils were needed but imports of types for typing loaded in the whole package

boreal umbra
#

@peak spoke wouldn't that only give you a runtime benefit if you never use those modules during that interpreter session for anything other than typing?

peak spoke
#

Yes, but overall it could reduce the spread of what's imported. The worst example of this I encountered was with sphinx where it was only necessary for compatibility with their format but the import of the utik function for that loaded the whole package through annotation imports

undone hare
#

I wouldn't mind if there's a significant difference in runtime performances

peak spoke
#

The separation of the import groups may also be useful

unkempt rock
#

i was reading about metaclasses, and i saw a super().__init__ being called on type on the metaclass __init__

#

but doing some tests, it works normally without using super init

#

there's any advantage to call the type constructor on a metaclass constructor?

deft pagoda
#

what works normally?

unkempt rock
#
class Meta(type):

    def __init__(cls, name, bases, dict):
        """There's no apparent issues not using this super __init__ here"""
        super().__init__(name, bases, dict)
deft pagoda
#

well, if that's all there is --- there's no point in the __init__ --- usually to justify it you need something else going on --- a common use is registering a class

#

but you can use __init_subclass__ for that now

#

!e

subclasses = {}
class MyMeta(type):
    def __init__(cls, name, bases, dict):
        subclasses[name] = cls
        super().__init__(name, bases, dict)

class MyBase(metaclass=MyMeta):
    pass

class MySubclass(MyBase):
    pass

print(subclasses)
fallen slateBOT
#

@deft pagoda :white_check_mark: Your eval job has completed with return code 0.

{'MyBase': <class '__main__.MyBase'>, 'MySubclass': <class '__main__.MySubclass'>}
deft pagoda
#

something like this

unkempt rock
#

👍

rustic stag
#
>>> tokenize._all_string_prefixes()
{'', 'Rf', 'Rb', 'Br', 'u', 'br', 'rf', 'RB', 'B', 'U', 'BR', 'rb', 'Fr', 'rB', 'rF', 'RF', 'F', 'fR', 'b', 'FR', 'f', 'R', 'fr', 'r', 'bR'}```
boreal umbra
#

@rustic stag what does this mean?

rustic stag
#

It means that Discord was showing me an old message! There was a discussion of mixed-case string prefixes. It turns out it was from about 30 hours ago, but Discord said it was new. So I was showing how to find all of the valid string prefixes. Sorry it was so out of date.

grave jolt
#

No worries, it's still relevant 🙂

boreal umbra
#

@rustic stag I wasn't asking as a moderation action, I just wanted to know lemon_hyperpleased

rustic stag
#

@boreal umbra no problem!

near condor
#

I'd say that depends on what you're doing in those try/finally blocks. Maybe use context managers, if it's a resource you're opening/closing? Or if it's a function that throws an exception when something can't be found (like str.index), you could write a wrapper that returns None instead.

#

If the control flow logic depends on exceptions being thrown, you might not be able to reduce it at all

#

Oh, and you could always extract those deeper finally blocks into their own functions, that could help too

gleaming rover
#

@rotund atlas okay, I spent some time working on it

#

I think I kind of have a solution

#

but it's also not really on topic for this channel

#

sure
@rotund atlas and ping me

molten onyx
#

exit stack from contextlib

grave jolt
brave badger
#

Is there a reason why qualified imports avoid circular dependencies within modules? e.g.

# engine.py
from . import environment as ev

# environment.py
from . import engine as en
```vs.
```python
# engine.py
from .environment import Environment

# environment.py
from .engine import Engine
grave jolt
#

Because if you do import module, it's fine if the module hasn't fully loaded yet.

#

so if you do

# a.py
import b

# b.py
import a

and run a.py, the first line of b.py will bind the module object to the name a, but that is like a pointer or something

#

But from module import name requires module to be fully loaded, because any line in it can redefine name

brave badger
#

Hmm

raven ridge
#

that's not exactly right: @brave badger, it's a question of what is available when. If you have:

# a.py
x = 1
import b

# b.py
from a import x
print(x)

everything will work totally fine. That's because modules are executed from top to bottom: when a is imported a module object is created for it, then the code in it starts executing: the x attribute of that module is set to 1, and then b is imported. When b runs it looks up the module object for a, finds it, looks up the x attribute of it, finds it, and everything works fine.

#

If you instead do:

# a.py
import b
x = 1

# b.py
from a import x
print(x)

then things won't work. When a is imported a module object is created for it, then the code in it starts executing: it executes import b before the x attribute has been set on it, and when b runs it looks up the module object for a, finds it, looks up the x attribute of it, and fails because that attribute doesn't exist - it isn't defined until after b has been imported, which can't happen because b requires it.

#

And if you instead do:

# a.py
import b
x = 1

# b.py
import a
print(a.x)

you'll get the exact same error even though you're not using a from import, because it still needs to access a.x at import time, and a.x still hasn't been defined when b is imported.

#

But if you do:

# a.py
import b
x = 1
b.print_x()

# b.py
import a

def print_x():
    print(a.x)

then everything works fine: when a runs it creates a module, then it imports b, and b looks up the module a and finds the (empty) module and saves a reference to it, and defines a new function (whose globals aren't yet resolved, so at this point a.x doesn't need to exist; it won't be an error until print_x() is called). Then, the import b finishes, a gets around to executing x=1 (setting the a.x attribute), and then it calls b.print_x(). Back in b, that now looks up the a.x attribute, and since it has now been set everything works fine.

brave badger
#

Right, thanks @raven ridge. Qualified imports worked best for me considering that I'm using postponed annotations and the fact that most of my calling code exists within functions and methods.

raven ridge
#

Yeah, importing the module instead of the attribute you need is definitely helpful for working around cycles, it's just helpful to know why that works.

ember spoke
#

so anyone here understands binary

#

i got an exam in 5 mins

#

ik this is python but i didnt know where to go for such question

weary minnow
#

i kinda understand binary

#

tho like conversion parity checks etc

languid dagger
#

@unkempt rock That is not relevant to this channel at all

unkempt rock
#

huh i didnt send anything

languid dagger
#

In case you're not aware we keep logs so please don't try and troll. I wouldn't have pinged otherwise.

boreal umbra
#

@stoic raptor this channel is for discussion. Please use it as intended

stoic raptor
#

Where can I post pictures

#

And why do I have developer role? @boreal umbra

boreal umbra
#

@stoic raptor The developer role is the base role, basically. If you have any other questions about how things work here, feel free to ask in #community-meta.

stoic raptor
#

Ok

rotund patrol
#

@clear rapids

fallen slateBOT
clear rapids
#

@rotund patrol ?

sacred yew
#

:thonk:

wicked holly
#

okay so im confused, i can print an f string, i can declare a variable to be equal to an f string, i can then return that variable from a function and it gets interpolated out properly when i later print the return of said function, but i can't directly return an f string from a function - it gives me a syntaxerror.

what's the delta between an f string and a variable equal to an f string that is causing the problem?

pliant tusk
#

what does your code look like?

wicked holly
#

i mean i can give you a very basic example of what i'm talking about - this is just somethign i had never experienced myself until someone in the general channel asked for help, and debugging it was confusing

#

def str(self):
#strrep = self.name +" is " + str(self.age) + " years old"
#return(strrep)
#return(f"{self.name} is {str(self.age)} years old")
return(self.name +" is " + str(self.age) + " years old")

#

the commented out lines include: using a variable and then returning that variable (works), returning a f string (what the person originally had, and i don't have a good sense of why it doesn't work), and then returning a concatenation of strings (also works)

peak sierra
#

I have to give a presentation on hiding redundancy, complexity anyone can help me please

pliant tusk
#

@wicked holly first off you dont need to do str(self.age) inside an fstring

#
>>> def s(a):
...     return f'{a}'
... 
>>> s(1)
'1'
>>> ``` also it works for me
wicked holly
#

@pliant tusk ugh okay the 'real problem' was i was pointing to a python2 interpreter in my shebang, nevermind me

buoyant timber
#

does anyone here have experience with the module "scikit-image" (aka skimage)

#

?

odd ether
buoyant timber
#

oh ok, im new to this discord, thanks for letting me know

#

thats an interesting system though

unkempt rock
#

I'm learning advanced algorithms & data structures in school right now and I'm a bit confused on if devs actually create their own algorithm libaries or just use stdlib?

I see python has sorted() but I can't find any documentation on it's source code/how it's implemented/it's running time/etc...Is it normal to make my own merge sort and my own bottom-up cut rod dynamic programming algo?

wicked holly
#

unless you have extremely good reasons not to, use stdlib

#

you might want to learn some about python profiling

unkempt rock
#

But there's like 15 different sorting algorithms and stdlib just has one from what I can tell and like I said I can't even find info on what kind of sort it is.

wicked holly
unkempt rock
#

And if I want to do sort the countless other ways since there's no such thing as 1 perfect sorting algorithm?

wicked holly
#

but from what you're describing, it sounds like what would be most useful would be to mess around with some python profiling tools, so you can have some reference points for comparing two implementations or two different algorithms?

feral cedar
#

timsort will probably be better than whatever you can come up with in python, since it's in C

#

it's a combination of insertion sort, and merge sort

unkempt rock
#

...ya but sometimes you'd want to use selection sort since it's better than insertion sort and merge sort for low n or nearly sorted arrays...I don't need a profiler, i know how these algorithms work. You don't just use 1 sorting algorithm for everything, that's ridiculous

feral cedar
#

tumsort accounts for that

#

so, yeah, you do use one sort for everything

unkempt rock
#

no you don't lmfao

feral cedar
#

sure

unkempt rock
#

you're not an engineer then, just a code monkey

feral cedar
#

my bad dude

unkempt rock
#

lmfao i forgot all the bootcamp kiddies think they're engineers now

feral cedar
#

I suggest you read the implementation of timsort

unkempt rock
#

shell sort, quicksort, heapsort

#

and then you've got things like union-find for the percolation problem that can be implemented all sorts of ways

#

ya i just looked up timsort, it's not usable for every situation at all

peak spoke
sharp plover
#

You'd rarely want to use anything other than the standard sort in python.

unkempt rock
#

i suggest you read an algorithms textbook on why you can't use 1 sort for everything and why that makes you not qualified to work in the field

sharp plover
#

There is also a heap implementation in the standard library, for when you need it.

feral cedar
#

my bad, you are clearly smarter, and a real engineer

unkempt rock
#

no you're just a code monkey that thinks he's an engineer because he read a book on python

#

but don't actually know CS

feral cedar
#

I'm sorry I offended you

#

try to beat the built-in sort with something you make though

unkempt rock
#

maybe you'll learn something

#

im sure its good for sorting your hentai tho

feral cedar
#

I don't see timsort on there

unkempt rock
#

i wonder why

#

its almost like its just a hybrid merge sort

feral cedar
#

I guess it's really just too slow to compare

unkempt rock
#

which is worse than quicksort in real life situations

#

wonder why its called quicksort?

#

its quick

#

you probably didn't learn that in your webshit bootcamp tho

feral cedar
#

you should contribute to cpython, change the implementation

#

you might be the next guido

undone hare
#

Now look at the current requirements for supporting sorting on an object, and tell me if you can have the same little requirements with quicksort

paper merlin
#

why not to use c++ or c?

boreal umbra
#

@hazy oak if you know something that another user doesn't, feel free to explain what that is, but the tone you're taking here is pretty condescending and not appropriate for our community.

undone hare
#

They left, but quadsort is also faster than quicksort hehe

boreal umbra
#

oh, perfect

feral cedar
#

lol

grave jolt
#

Actually, I once benchmarked that a pure python radix sort did a better job than timsort starting with some input size 🤔

#

but that's true for random data

boreal umbra
#

isn't part of the point of timsort that it's O(n) if the list is already sorted?

feral cedar
#

yeah because it's smarter than a normal merge sort

boreal umbra
#

is log-linear the best possible runtime for very not-sorted data?

#

it obviously can't be linear

#

(right?)

grave jolt
#

O(n logn) is optimal for a comparison sort

boreal umbra
#

isn't log-linear what nlogn is?

grave jolt
#

yeah

#

but there's also bucket sort, which can be better

#

but it doesn't apply to all data

wicked holly
#

the guy just seemed like a kid having a meltdown

boreal umbra
#

@wicked holly probably, but they're gone now, so let's talk about Python 😄

wicked holly
#

he didn't seem to be able of doing basic google searches or profiling on his own, but lashed out at everyone

last mural
#

who is it

#

just curious

boreal umbra
#

@last mural tony thot. You can scroll up to read it but let's not waste more time discussing it.

wicked holly
#

lol

last mural
#

:P

wicked holly
#

when people get hyper bent out of shape about performance vis python it just sort of makes me roll my eyes... like just wait until you learn about the interpretation lock...

#

but do they seriously use python in algorithms courses nowadays? we were still using c as of 10 years ago.

boreal umbra
#

@wicked holly I think Python is a good language for learning A&DS because you can focus on how the problem is being solved and not on the implementation details of the language.

feral cedar
#

mit uses python

wicked holly
#

what a world

feral cedar
#

a lot of places use Java I think

boreal umbra
#

my uni uses Java for most classes

wicked holly
#

most of the programming-specific courses i took were through the engineering department, which were separate from the CS department

last mural
#

i need a bit of cpp help, not sure if i can get any here
the other server which is specifically for cpp isn't active

#

oops wrong channel

wicked holly
#

if it's C++11 or older i can probably help you in pms

last mural
#

mkay

#

but i can't dm you

wicked holly
#

ok i added friend, i think i changed some settings due to some aggressive spamming i was getting on another server

desert peak
tacit hawk
#

Is there any problem in keeping a reference to an exception that has a traceback?

peak spoke
#

It'll keep references to the frame, keeping local etc. alive but the gc should clean them up when it runs if it isn't disabled

tacit hawk
#

hm OK. I see asyncio's Future keeps reference to the exception set by set_exception(). I need to keep a reference because I want to raise it later.

sacred yew
#

just remember to del after you're done using it

boreal umbra
#

@sacred yew what does that do?

desert peak
#

@boreal umbra reduces the refcount

#

https://stackoverflow.com/a/6798042
does anyone know why __call__ is being invoked for the new class instance versus __init__/__new__? I don't really understand metaclasses yet.

spark magnet
#

@desert peak you create an instance of a class by calling it: obj = MyClass()

desert peak
#

Yes, but doesn't that invoke __init__/__new__? Wouldn't __call__ be invoked by doing MyClass()()?

spark magnet
#

though i have to tell you, I am opposed to these kinds of singletons.

#

i'm not sure why it isn't __init__

#

oh, because you don't want a new object, so you override __call__ to prevent it from constructing an object.

#

it's better to just skip all this though

desert peak
#

@spark magnet my use-case: I'm trying to create an app-wide aiohttp.ClientSession object that will refresh credentials from a vault on bad response from an API I'm integrating to.

spark magnet
#

why not just have a function that returns the object to use?

desert peak
#

so I'm creating a singleton session that will use FastAPI's dependency injection

spark magnet
#

why is SomeClass() better than some_class() ? It's easier to write the function.

desert peak
#

because all I'm doing is implementing __call__ on a class

#

which is how class-based callables work for fastapi's DI

spark magnet
#

but you're puzzling through metaclasses.

#

you could pass this function to the DI

desert peak
#

mostly for the benefit of singletons since I only want one session and I want it to hook into the http lifecycle to refresh credentials on bad responses from my API

#

while also being easier to test

spark magnet
#

right, the function could handle the singleton-ness of it

desert peak
#

but wouldn't I have to rely on global and a module member with that approach?

spark magnet
#

yes. instead you have a global hidden inside a metaclass somewhere.

#

it's not so different, except we can understand the function.

desert peak
#

that's true, different approaches to the same goal

spark magnet
#

Singleton._instances is a global

desert peak
#

with a less-hackable way for my coworkers to mutate it though 🙂

spark magnet
#

if your coworkers would fiddle with the global, you have a social issue, not a technical one 🙂

desert peak
#

this is commonly the answer in tech

#

but sometimes you can't fix the social issue

spark magnet
#

it seems like Java people wrote a book about patterns, and now everyone thinks Singletons are good and important.

desert peak
#

I wish python had more immutable structures

spark magnet
#

yes, lots of people do.

#

but Singleton won't protect you from the real risk, which is someone mutating the one object.

#

(in fact, it increases the risk by lying about object construction)

#

obj = SomeClass() # is this my object, or shared? ¯\_(ツ)_/¯

tacit hawk
#

just remember to del after you're done using it
@sacred yew Well I am taking Future as reference, I don't see where they manually clear the reference

cloud crypt
#

singletons are only to be used as sentinels or related things in places imo

#

otherwise they’re used for globally manipulating on stuff which is prone to data races

spark magnet
#

My main concern is how they are made. There's no reason in Python to write a misleading class to do it.

elder lodge
#

I always avoid globals and shared state stuff. The bigger the project the messier it gets and more prone to side effects

desert peak
#

my use-case is very defined here, I'm sharing an aiohttp session and need to refresh credentials from a vault on API failure

tacit hawk
#

and a messed project tends to be more messed

#

like the broken window

elder lodge
#

I’m a big fan of always passing in what the function needs

spark magnet
#

@desert peak yes, that's a great reason to control object creation. You just don't need metaclasses to do it.

elder lodge
#

I never heard of meta classes and stuff like that until I started touching django projects. It drives me nuts

tacit hawk
#

calling a Class() or a function() should be transparent, no?

elder lodge
#

What happened to good old oop

desert peak
#

metaclasses are pretty fundamental to oop.. lol

elder lodge
#

In what way

cloud crypt
#

definitely not

desert peak
spark magnet
#

i don't know if I've ever written a metaclass

elder lodge
#

Me either

#

I never want to

desert peak
#

frameworks are a pretty major way metaclasses are utilized

elder lodge
#

They’re not legible in any way

tacit hawk
#

I see frameworks like to use metaclasses because it makes them more usable

spark magnet
#

hmm, i have written them.

desert peak
#

Declarative programming is another thing I see popping up in this thread

spark magnet
#

if you have a need to affect the behavior of bunch of classes when the class is defined, a metaclass is a way to do it.

#

(but lying Singletons are still bad 🙂 )

desert peak
#

it looks like metaclasses are the reason __new__ exists

cloud crypt
#
from typing import Optional, Type, TypeVar

S = TypeVar("S", bound="Singleton")


class SingletonMeta(type):
    def __repr__(cls) -> str:
        return f"<singleton class {cls.__name__}>"


class Singleton(metaclass=SingletonMeta):
    INSTANCE: Optional[S] = None

    def __new__(cls: Type[S], *args, **kwargs) -> S:
        if cls.INSTANCE is None:
            cls.INSTANCE = super().__new__(cls)

        return cls.INSTANCE

    def __repr__(self) -> str:
        return f"<singleton {self.__class__.__name__}>"``` that's my way to write them
spark magnet
#

@cloud crypt that's bad

elder lodge
#

That looks disgusting

cloud crypt
#

why is

desert peak
#

I kind of like it 😆

cloud crypt
#

lol

#

tell me
tell me

spark magnet
#

@cloud crypt because your class is lying, and there's no need.

cloud crypt
#

define lying

tacit hawk
#

Declarative programming is another thing I see popping up in this thread
@desert peak Yeah, django's Model uses a metaclass that allows them to be written in a declarative manner

spark magnet
#

"I wrote code that looked like I was making a new object, but I got an existing object instead"

elder lodge
#

@nekit what are you trying to do?

#

@cloud crypt

desert peak
#

mmmm, by that extension, do you think __call__ is bad, too?

cloud crypt
#

I just showed a way to do that if you do it

spark magnet
#

@cloud crypt why not just use a function to manage the object creation?

cloud crypt
#

I just showed a way to do that if you do it

spark magnet
#

"if you want to do a bad thing, here's how to do it:.."

desert peak
#

I mean, this is kind of python's fault for calling 3 magic methods on object instantiation

elder lodge
#

@spark magnet my use-case: I'm trying to create an app-wide aiohttp.ClientSession object that will refresh credentials from a vault on bad response from an API I'm integrating to.

spark magnet
#

this is java's fault for making people think everything has to be handled in a class

elder lodge
#

Are you trying to rescue the behavior on a failed request? @desert peak

spark magnet
#

@desert peak you can avoid all the magic methods. write a function.

desert peak
#

@elder lodge well, the credentials can expire at any time; they rotate daily

elder lodge
#

If you get a bad response from the api I don’t think the solution is to refresh credentials in the same request and try again

desert peak
#

it's bad UX to have a request fail randomly due to authorization when it can be fixed

tacit hawk
#

@elder lodge cant the object be passed as parameter to others that needs it?

elder lodge
#

Why don’t you have something that tells you about the expiration of your token?

tacit hawk
#

I think singleton is used because people don't want to pass the references

spark magnet
#

it's bad UX to have an object construction not construct an object.

tacit hawk
#

so they make it a global object

elder lodge
#

Aren’t singletons global?

desert peak
#

the tools available to me don't provide that information @elder lodge

spark magnet
#

@tacit hawk I understand the convenience of the global. I'm just suggesting a simpler and clearer way to do it.

boreal umbra
#

@elder lodge if you create a singleton class, that's not guaranteed. None is global, I guess.

desert peak
#

I have this information about my environment: credentials rotate every 24 hrs (+/-2hr), the API I retrieve the credentials from is rate limited, and during rotation gives me a rotation-in-progress message

spark magnet
#

I think an object that hides the credential rotation is a good idea

desert peak
#

@boreal umbra None, (), True and False are all singletons.

spark magnet
#

so are small integers

#

and some strings

desert peak
#

and certain chars/strings, no?

boreal umbra
#

I hadn't heard about the empty tuple being a singleton but it makes sense given that True and False are aliases for 1 and 0.

spark magnet
#

but most of that is just an optimization, code would work the same even if they weren't.

desert peak
#

@spark magnet I haven't thought of that avenue. Might be worth writing a decorator that caches credentials and automatically rotates underneath the rate limit

elder lodge
#

I hate decorators too

spark magnet
#

@desert peak i thought i was saying that your object was a good idea

boreal umbra
#

@elder lodge why

smoky turret
#

not exactly aliases, bool is a subclass of int, with true and false just having the same numeric value as 1 and 0

elder lodge
#

I hate decorators and I hate metaclasses

cloud crypt
#

no

#

it ain’t

spark magnet
#

@elder lodge we got that. but why?

cloud crypt
#

or is it

boreal umbra
#

I'm clearly a failure. One moment.

cloud crypt
#

I guess

#

I mean we all are sometimes

#

assert that man

elder lodge
#

I hate anything that hides implementation and makes code illegible for other developers

boreal umbra
#

!e print(True is 1)

fallen slateBOT
#

@boreal umbra :white_check_mark: Your eval job has completed with return code 0.

001 | <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
002 | False
boreal umbra
#

Guess not.

cloud crypt
#

yes

#

exactly

desert peak
#

"hides implementation"

#

that's called an abstraction.

tacit hawk
#

it's bad UX to have an object construction not construct an object.
@spark magnet well I think the singletons would carry Singleton in the name, but without any hint that's really bad

elder lodge
#

Yea I know what abstractions are

cloud crypt
#

okay you hate metaclasses, sure

desert peak
#

I guess you're off writing asm by hand then

cloud crypt
#

have you ever used enum?

spark magnet
#

@tacit hawk there's no reason to write lying Singleton classes

boreal umbra
#

I thought true and false referred to the same object as the 1 and 0 allocated when the interpreter starts. I'm not sure what I thought the bool class was doing.

spark magnet
#

I hate anything that hides implementation and makes code illegible for other developers
@elder lodge Don't functions hide implementation?

cloud crypt
#

bool class is really just

#

defining repr() and str()

desert peak
#

!e

print(help(bool))
fallen slateBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

desert peak
#

It's more than that, @cloud crypt I'm pretty sure it subclasses int

boreal umbra
#

it does

cloud crypt
#

it does

tacit hawk
#

I hate anything that hides implementation and makes code illegible for other developers
@elder lodge generally people don't want to know the implementation. The documentation is enough.

elder lodge
#

@spark magnet yes but I guess what I’m saying is , from a readability standpoint you look at a function and then it’s dressed with decorators that can mutate things and you have to dig into them and i don’t like that

cloud crypt
#

and I was talking about altered behavior on bools

desert peak
#

why do you care about implementation?

#

you should only care about its API

cloud crypt
#

again

spark magnet
#

@elder lodge but that's like say, "my functions call other functions, so i have to know what those functions do"

opal flame
#

Is anyone here experienced with writing integration tests?

tacit hawk
#

just trust the tool or don't use them

desert peak
#

decorators are legit one of my favorite features of Python

boreal umbra
smoky turret
#

I agree, decorators are really nice

desert peak
#

I especially like the way different frameworks have utilized them

opal flame
#

@boreal umbra thanks

tacit hawk
#

because they can change behavior without changing the code

elder lodge
#

@spark magnet sure I get that. I just don’t find them readable at all. Especially when you have multiple decorators. It’s a nice convenient feature but many languages don’t have them and are fine

cloud crypt
#
from enum import Flag

class Color(Flag):
    BLACK = 0
    RED = 1
    GREEN = 2
    BLUE = 4
    YELLOW = RED | GREEN
    CYAN = GREEN | BLUE
    PURPLE = RED | BLUE
    WHITE = RED | GREEN | BLUE``` ever thought what happens behind that
smoky turret
#

my understanding, from listening to raymon hettingers keynote about being a core dev, is that the enum module is a massive overuse of pythons features

desert peak
#

many languages are far more verbose as a result

boreal umbra
#

I thought you could only pipe enums after the class has been defined

desert peak
#

the enum module is disgusting and they should've implemented enums as a native language feature

boreal umbra
#

I mean, it's part of the standard library

#

what's disgusting about it?

desert peak
#

but it's not part of the language

boreal umbra
#

you can't always distinguish between the language and the stdlib

tacit hawk
#

you mean builtin? well it's just a minor detail

cloud crypt
#

@smoky turret yeah it definitely hella is, https://github.com/nekitdev/enums.py I have written a reimplementation of that and I really feel weird about it

desert peak
#

enums are such a fundamental part of programming that they should've had their own grammar imo. I would love algebraic types

cloud crypt
#

I didn’t like _sunders_ and related so I rewrote it for myself

magic python
desert peak
#

don't use imperative setup

#

use setup.cfg

boreal umbra
#

I don't really use enums so I'm not sure what they're missing

cloud crypt
#

they are not really missing anything

#

I only added ability to have control over members, some other funny metaprogramming features and stuff

#

what really sucks is MRO

cloud crypt
#

because types kinda steal your methods

magic python
#

@desert peak i thought that was being replaced by pyproject.toml

cloud crypt
#

@desert peak that is a much different concept of enums — but yeah, definitely

desert peak
#

Kind of but not really?

#

two docs I always tag at the start of all my config^

magic python
#

@desert peak cool thanks - it seems the link i sent was wrong still tho?

cloud crypt
magic python
#

also - most of the projects i see seem to use setup.py, so I'm not sure i follow what's wrong with it

desert peak
#

You are missing that they imported the module, not from the module.

magic python
#

ah ofc, that was stupid, didn't read setuptools. there at all for some reason

north root
#

i really don’t see a need for enums like Rust in Python

magic python
#

anything i should look at re the cfg comment tho? I don't really get it

north root
#

in Rust, it’s basically essential

desert peak
#

with the pattern matching PEP, they would be very nice to have

north root
#

in Python, not so much

desert peak
#

@magic python It's a way to "declare" your options instead of writing them "imperatively"

#

look up declarative v. imperative programming

#

less implementation details needed for declarative

#

you just tell the program what state it should be in

#

and let the framework handle the rest

magic python
#

sure, ggplot vs mpl etc

#

i'm familiar with the concept, just that i generally seem to see setup.py

desert peak
#

you still use setup.py with setup.cfg

#

you just leave an empty setup()

#

for backwards compatibility

magic python
#

maybe i'll get it later then, i don't do much packaging, doesn't seem like a big deal atm tho

desert peak
#

I do a ton of packaging and I hate everything about how Python handles it

magic python
#

the pypa example of setup.cfg is pretty minimal too

#

it's all in .py not cfg, so eh, not very clear

elder lodge
#
When the need arises, however, Python provides a capability that not all object-oriented languages support: you can get under the hood and define custom metaclasses. The use of custom metaclasses is somewhat controversial, as suggested by the following quote from Tim Peters, the Python guru who authored the Zen of Python:

“Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don’t (the people who actually need them know with certainty that they need them, and don’t need an explanation about why).”

— Tim Peters
magic python
#

oh that sample project is garbage

ok good ha

desert peak
magic python
#

to get time-series data on local bandwidth availability
lol, co-worker and i were looking for exactly this earlier

desert peak
#

I saw it on reddit and wrote a scheduler and such around it - I was planning on making an API to generate the plots, but haven't had time lately

#

I went down the rabbithole of getting CI/CD implemented and exploring using tabs in python over spaces and yapf and and and...

magic python
#

rabbithole of getting CI/CD implemented
been trying to do that with R and renv... makes you think python envs are managed well

desert peak
#

my plan is to host it on pip eventually when I get another window of time

#

well, CI/CD isn't difficult, actually. It's the pipeline tool decision that I was struggling with making decisions on like linting and auto formatting, etc.

magic python
#

only think I've used cfg for is flake8 - toml is used for pylint / pytest errors etc, and that's about it ( no packaging )

desert peak
#

pytest supports pyproject now? that's new. it also supports the cfg file

magic python
#

yea

desert peak
#

I tried using Poetry for this but was dissatisfied with the way it was handling packaging

#

for distribution

magic python
#

i cba to learn anything fancy i don't think, i just want to package things, which is why using setup.py seemed "standard"

#

but if it's shifted/ing to cfg maybe i'll do that

desert peak
#

I think people use setup.py because there's so much documentation and examples on that, but setup.cfg is a much nicer experience. I'm not sure how much support pyproject.toml has in the broader ecosystem since it's such a "newer" PEP, but it'll catch on eventually

#

personally I think pip and its ecosystem need to be torn down and started fresh

magic python
#

because there's so much documentation and examples on that
yeah exactly this, there's a load

#

i've only used R and python, so pythons seems nice I guess

desert peak
#

try using almost anything else. nuget, cargo, yarn, all much nicer experiences

#

python's is a problem because you can have broken environments as a default

magic python
#

not sure what a broken env is 🤔

#

conflicting packages?

desert peak
#

yes

magic python
#

i use pip-tools compile for that

desert peak
#

because python can only load one version of a package

#

things like poetry try to solve that problem which is why it sees adoption

magic python
#

what's pip-tools missing that poetry gives

desert peak
#

pip-tools only pins dependencies, it doesn't resolve them. poetry resolves all your dependencies against each other so you never have conflicting versions (this assumes some level of dependency pinning in your dependencies, however)

magic python
#

oh, i thought that pip-tools compile solved dependencies?

#

whoops 🤦‍♂️

desert peak
#

I'm looking at the documentation right now

#

it's not clear yet

magic python
#

yeah i'd go with the docs over me ha

#

usually i have something like pandas in requirements.in and pip compile will create requirements.txt with the version info and stuff in there

desert peak
#

yeah, compile just pins your dependencies

magic python
#

I think that it does deps as i seem to recall pandas-profiling holding the pandas version back as it was dependent on pandas <=0.28 or something like that... i'm not too sure tho

desert peak
#

it doesn't do any resolving of its own

magic python
#

ah ok cheers, good to know

desert peak
#

pip has a resolver, but it doesn't resolve against all packages in an environment like poetry will do

#

it only exists to resolve versions against pypi

#

poetry also generates lockfiles, so you always get the same version of dependencies and it doesn't have to re-run resolution on install

magic python
#

requirements.txt is a lock file? or not

desert peak
#

nope, requirements is just that - dependencies for your app

#

unless you pin exact versions for every dependency, you can end up with different versions between installs

magic python
#

ok, interesting... i had it in my head that poetry was some fancy new thing that might be gone soon for some reason.... perhaps i should consider it if it's used more

#

unless you pin exact versions for every dependency
that is what pip-tools compile seems to do afaict

#

idk why poetry does virtualenvs too, that seems annoying

desert peak
#

you can also configure virtualenvs to be created in your project if you don't like the centralized venv approach:

$ poetry config virtualenvs.in-project true
magic python
#

i do use ~/.virtualenvs but i have stuff that i'm used to I guess so it goes from changing from pip-tools -> poetry for dep management to changing other things as well

elder lodge
#

how does django do this:

b = Blog.objects.get(name="Cheddar Talk")

how does objects have a database connection automatically?

spark magnet
#

a global someplace

elder lodge
#
def get_blog_by_id(session: Session, blog_id: int) -> Blog:
   return session.query(Blog).filter(Blog.id == blog_id).one()

is the above less preferred because it's verbose compared to

Blog.objects.get(id=blog_id)

spark magnet
#

@elder lodge it would be inconvenient to have to pass a session explicitly everywhere you needed it, including into templates.

#

@elder lodge avoiding globals is a good instinct. but sometimes a well-placed global makes things a lot easier.

unkempt rock
smoky turret
#

missing a closing bracket )

unkempt rock
#

My bad

smoky turret
#

also, not the right channel for this

unkempt rock
#

Can I add you as a friend?

smoky turret
#

uhh, Im not looking to be someones goto for debugging

feral cedar
#

@unkempt rock when you see that much repetition, that's a sign there's a better way to do what you're doing

unkempt rock
#

Such AS.

feral cedar
unkempt rock
#

Isnt clearly listed.

feral cedar
#

huh? it's the third category in the list of channels

#

a dictionary is probably your best bet for this

#

you should take a help channel, there are a few things wrong with your program

elder lodge
#

anyone know if django.db is available as an external non-django package in some form? there are a lot of niceties it has--would be nice to be able to use something like that for non-django projects

spark magnet
#

@elder lodge it's not available separately

desert peak
#

Django ORM is its own thing for use in its framework. Checkout SQLAlchemy for a non-Django alternative @elder lodge

forest pawn
#

It's not available separately, but it is totally possible for you to use Django just for its ORM bits. You'll need to run django.setup() at one point in your program before starting to use the models and the like (and you'll need to set up settings) but it's Just Python ™️

main folio
#

embedding python in c++

#

?

boreal umbra
#

@main folio doesn't it usually go the other way around?

main folio
#

nope

#

using python for a backend is garbage code

#

sorry cython not python

#

cython with a c

#

python is event worse for a backend thou

#

but seriously how do you embed cython in c++

#

is there a cython chat

feral cedar
spark magnet
#

python is event worse for a backend thou
@main folio what is so terrible about python for a backend?

torpid pollen
#

Any statement in a program can change the value of a global variable. If you find that the wrong value is being stored in a global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. In a program with thousands of lines of code, this can be difficult.

main folio
#

@spark magnet speed

spark magnet
#

@torpid pollen are you pasting text from somewhere else?

main folio
#

also what he said

spark magnet
#

@main folio what does your program do?

main folio
#

stockdata

spark magnet
#

is it doing a lot of calcuation?

main folio
#

yes

#

that's why I need c

spark magnet
#

numpy could help

sacred yew
#

well you shouldn't be doing calcs in python

#

use a lib with c extensions

main folio
#

c is faster

#

and better

sacred yew
#

yes that's why you use c extensions

main folio
#

raw c is the best

sacred yew
#

but c is not "better"

main folio
#

it is

spark magnet
#

we don't need to debate this

sacred yew
#

dev time >>> run time

teal yacht
#

3000 iq hours

main folio
#

yes

#

build the best product possible event if it kills you in the proccess

sacred yew
#

wut

main folio
#

THE PRODUCT MUST EMBODY PERFECTION

sacred yew
#

ok he's trolling

main folio
#

I'm not

#

I just want to deliver the best product possible

sacred yew
#

write raw asm if you care about sperd

#

goodbye

main folio
#

i have

#

before

sacred yew
#

for the entire codebase

main folio
#

some

sacred yew
#

since that's what your argument is for using all c

torpid pollen
#

@torpid pollen are you pasting text from somewhere else?
@spark magnet no

sacred yew
#

so write raw asm for an entire codebase because it's "better"

main folio
#

asembly isnt much faster then c

sacred yew
#

c isn't much faster than python with c extensions

main folio
#

alot of the time c runs as fast as assembly

#

python on the other hand is at best like 50 times slower then assembly

#

@fickle atlas, its way faster trust me

#

unless you're talking about cython

#

cython is amazing

sacred yew
#

You pinged the wrong person

main folio
#

what language is numpy written in

spark magnet
#

@main folio we get it, we're not trying to change your mind

main folio
#

good

#

seriously this is ridiculous

sacred yew
#

c isn't much faster than python with c extensions
@sacred yew

main folio
#

it s way faster

teal yacht
#

I don't think this is the correct channel for zealotry

#

let alone blatant ignorance

sacred yew
#

I have concluded that you are incapable of reading a graph

main folio
#

want speed for numeric calculations use fortran

spark magnet
#

we really don't have to continue this pissing match

main folio
#

Ive read the graph

#

c++ had less time

#

thats all that matters

#

c would've probably done it better

#

c is faster then c++

#

you know that right? @sacred yew

teal yacht
#

seriously go to off-topic if you want to troll or something

spark magnet
#

@main folio really, let's stop

teal yacht
#

you're cluttering the chat with non-sense

main folio
#

I'll stop

desert peak
#

anyone have luck deploying packages to pypi w/ poetry?

#

never deployed anything there, so this is my first foray

main folio
#

optimized cython is faster

desert peak
#

Stop it and leave.

main folio
#

pip3 install cython

#

I'm trying to help

#

this time

spark magnet
#

I'm trying to help
@main folio no you aren't. be nice.

feral cedar
#

stop being rude, please

boreal umbra
#

@main folio this channel is specifically for discussing the Python language itself. It seems like you aren't really interested in doing that.

main folio
#

cython is an extention of the language of python

spark magnet
#

yes, but no one was asking how to make things faster.

boreal umbra
#

it's more of a superset of Python. However it seems like you're not really listening to what the other members here are saying.

main folio
#

cython is an area I know

#

I cant help anyone in an unkown area

boreal umbra
#

If you want to do numerical calculations faster, but still do it in Python, you can use numpy and pandas. If that's not enough, you can write the whole thing in C. That's about all there is to say about that.

spark magnet
#

cython is an area I know
@main folio when someone asks about cython, we will be glad to have your expertise.

white prism
#

hi

#

help me install matplotlib this module

boreal umbra
#

@main folio I'd appreciate it if you take a different approach going forward. Comments like "build the best product possible event if it kills you in the proccess" and "THE PRODUCT MUST EMBODY PERFECTION" show that you're more interested in playing around than engaging with people here.

gleaming rover
main folio
#

I'm being honest

#

if the product isnt good nobody will buy it

spark magnet
#

that's off-topic

white prism
#

@white prism this is a channel for discussion of the language. try #❓|how-to-get-help or #python-discussion? thanks!
@gleaming rover I don't have permission to write to p-generator how do I get it?

gleaming rover
#

sorry, didn't understand that

main folio
#

matplotlib is usually include

#

d

gleaming rover
#

matplotlib is usually include
@main folio it's included if you install Anaconda, but not otherwise.

spark magnet
#

matplotlib is not in the stdlib, it has to be installed.

main folio
#

I was about to say pip3 install matplotlib

desert peak
#

sounds like they're being removed in short order

#

why is curl | sh or curl | python - such a popular install method?

north root
#

!ban 760221432466243604 user impersonation

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied ban to @unique notch permanently.

spark magnet
#

why is curl | sh or curl | python - such a popular install method?
@desert peak it works

desert peak
#

right, I'm curious why they don't get into sys pkg mgrs or pip

spark magnet
#

pkg mgrs mean getting packaged for a bunch of OS's, pip means your users have to have pip working

sacred yew
#

at least do wget, then open a text editor to check, then do python3

desert peak
#

oh you mean, curl | SUDO python3 - got it

sacred yew
#

otherwise you're just pwning yourself

#

oh no

#

sudo python3 is even worse

desert peak
#

I was installing oh-my-zsh and poetry on my WSL2 instance and they both go the curl | sh route which is why I was expressing my dismay above

sacred yew
#

isn't poetry in pypi?

#

at least the omz one kinda makes sense

desert peak
#

it is, but not the recommended installation route

sacred yew
#

bruh why is the manual inspection one below the self pwn ones

desert peak
#

right

sacred yew
#

?

desert peak
split chasm
#

congrats

#

recently did the same

quasi urchin
#

Anyone here knows selneium?

amber nexus
#

@quasi urchin Not the channel for that

unkempt rock
#

Is there a way to host python server with open port for free?

meager idol
#

There is variation in answer of integration with comparing using scipy.integrate. can anyone help!? How is it so?

undone hare
random bison
#

why doesnt it work```python
def saveText(event=None):
global fileName

if not fileName :
    inputName = asksaveasfile(mode='w', title="Save the file", defaultextension=".txt", filetypes = (("Python","*.py"),("Text File","*.txt"),("all files","*.*")))
else:
    inputName = fileName

if inputName:
    fileName = inputName
    content = textField.get(1.0, END)
    with open(fileName, "a") as theFile:
        theFile.write(content)
        root.title('{}'.format(os.path.basename(fileName)))
#

its not writing into the file

grave jolt
random bison
#

ok

amber nimbus
#

Can anyone suggest me which path to follow for gsoc 2021

#

And contributing in python open source

desert peak
unkempt rock
#

how do I make an if-statement to check if something is in a file name? Like:
if 'data' in file.name:

sacred tinsel
#

that should work if file.name is a string

wide shuttle
#

Sounds like a question you should ask in a help channel

#

This channel is to discuss the Python programming language itself, from a higher-level perspective

unkempt rock
#

ah I see

#

my bad

#

I saw the other code and thought this was the right place

desert peak
#

the other people were also redirected to a help channel..

unkempt rock
#

yes lol

#

i failed to read that

desert peak
#

anyone have experience passing async ctx mgrs around?

#

I think I'm seeing a double-free happening

grave jolt
desert peak
#

wasn't aware there was a channel for that

faint compass
#

I have a PyTest question. Is it possible to parameterize a test with different fixtures? as in pytest.mark.paramaterize('fixture', [(fixture_a, ), (fixture_b,)]) ?

undone hare
boreal umbra
#

@tepid ermine Akrays directed you to #❓|how-to-get-help. Please read that for instructions as to how to open a help channel, since this one is strictly for discussion. Going forward, please also don't write long, low-content messages like "plzzzzzzzz" where there are many Zs that wrap around numerous times. Thanks!

#

!mute 755050058193567744 1h Please stop spamming. When this mute ends, you can open a help channel and ask for help with what you're doing.

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied mute to @tepid ermine until 2020-10-30 19:41 (59 minutes and 58 seconds).

barren quest
#

Hi i want to know can i push change with branch name “local-branch” in local to branch name “remote-branch” in remote repo?

boreal umbra
#

@barren quest try asking in #tools-and-devops. This channel is strictly for Python talk.

hollow rose
#

Are requests faster if i pass the allow_redirects=False parameter in python? Like if i make a GET request to google.com for example and it redirects me to google.de does it do another GET request to google.de which it would'nt if I pass the allow_redirects=False parameter?

spark magnet
#

@hollow rose if you don't allow redirects, you won't get the data you want.

hollow rose
#

i do

#

anyways thats not what i was asking for

#

i just want to know if its faster

spark magnet
#

it will be faster, but you won't get your data, will you?

hollow rose
#

yes i will 😉

#

thanks

#

so its does another get request right?

#

if i allow redirects

spark magnet
#

@hollow rose have you tried it without the redirects?

#

yes, it will make another get request.

hollow rose
#

yeah i did

#

im posting some data

#

and theres a location header in the response

spark magnet
#

oh, then you aren't trying to get data

hollow rose
#

so it will redirect me without the param to false right

#

it will take longer than with allow_redirects=False

spark magnet
#

yes, it will.

hollow rose
#

appreciate it! 🙂

unkempt rock
#

what was the first computer language

#

😮

boreal umbra
#

@unkempt rock Not Python, unfortunately

#

this channel is specifically for talking about Python though

unkempt rock
#

OOH

#

mb

boreal umbra
#

@unkempt rock no problem; be sure to check out the channel description for any channel before you comment in it for the first time.

gleaming rover
unborn osprey
#

kk sorry

gleaming rover
#

np!

feral cedar
#

?

boreal umbra
#

@crude glen if I understand the screenshot correctly, it looks like your bot does something that Discord feels is a waste of their resources. However that would be a better topic for #discord-bots

surreal jacinth
#

Anyone have any favorite libraries for parsing extended, complex bitfields?

#

I tried ‘struct’ out but it appears to deal primarily in values that align nicely with byte boundaries

#

In my case I have some unsigned ints stored in 7 bits, or 10 bits, etc

cedar kiln
#

is there anyone that would be able to take a look a this for me

#

I am not getting an output; i think i am missing some type of a function but i am not entirely sure

surreal jacinth
#

I can in a moment

cedar kiln
#

Thank you

surreal jacinth
#

presumably your “hello world” prints adequately, right?

boreal umbra
cedar kiln
#

if i remove everything below ## this is the second part and run it it will print the helloworld statment

#

with that second part that is what is messing it up

surreal jacinth
#

feel free to ping me directly its no sweat if folks dont want the discussion here

cedar kiln
#

bet thank you

surreal jacinth
#

Tho I’d still love to get folks’ thoughts on bitfield parsing 🙂

#

In JavaScript I always just do it manually but I thought I’d see if I can be cuter in Python...

smoky turret
#

There any way to put up some pop up or any kind of disclaimer that this channel in particular is not for help? we seem to get people asking for help in here like every hour

surreal jacinth
#

Well, “advanced discussion” certainly seems to imply discussion re: python with advanced developers or something.

naming and off by ones...

#

Though fairchild above lost interest in my helping him once I refused to simply correct the script... 😑

feral cedar
#

we've tried many many variations on the name, this one seems to work the best so far

surreal jacinth
#

advanced-discussion-not-hell

#

*help

#

hell may work too

smoky turret
#

metaclass hell

unkempt rock
#

python-meta-discussion

surreal jacinth
#

meta discussion has a nice ring

#

supposing the convo is sufficiently meta

boreal umbra
#

We discussed a lot of different names, and I actually suggested having "no-help" just to see how the rest of the staff would feel about that. However we want all our channels to be welcoming.

surreal jacinth
#

You got it

smoky turret
#

advanced-usage-no-help

boreal umbra
#

I feel like I make class method constructors a lot

#

Is that weird?

smoky turret
#

naw, alternative constructors are nice

boreal umbra
#

Like most of my classes these days have one.

smoky turret
#

what are these classes of?

boreal umbra
#

Uh

#

Reading files

#

It's really niche stuff.

crisp zinc
#

I use a function overloading package

#

it's a good tool to remove redundant constructors with different names for different types

boreal umbra
#

@crisp zinc function overloading isn't well supported by python because signatures aren't typed

crisp zinc
#

Let me show you something

surreal jacinth
#

Is there a reason youre finding them useful in particular?

#

It’s always kind of hard to say whats appropriate in the absence of context

crisp zinc
#

That is not the same thing @gritty pebble

#

It doesn't allow for multiple implementations

#

All implementations need to be explicitly called from the final function which is kinda dirty

near coral
#

not sure when I would use this

#

but...I am sure I will come across a situation

fresh cargo
#

The http module doesn't have status code 418 before 3.9?

peak spoke
#

No

fresh cargo
#

Oh no I'll have to upgrade

robust lily
#

hi

cloud crypt
#

upgrading python for a joke

#

haha

smoky turret
#

oi, thats a very important response code

#

its up there in the standards with rfc2549

dapper tinsel
#

?

unkempt rock
#

?

safe hedge
#

Assuming those ? are you asking about the response code thing.

418 I'm a teapot

#

It's from some April Fools

robust lily
#

???

signal tide
#

#advanced-http-discussion but 418 was actually described as having a serious purpose: "it identifies many of the ways in which HTTP has been extended inappropriately", the protocol is actually fairly interesting if you get around the whole coffee analogy https://tools.ietf.org/html/rfc2324

unkempt rock
raven ridge
#

@signal tide the RFC serves a serious purpose, not the 418 status code, to be clear.

molten onyx
#

eh? it's an april fools joke

#

or do you mean the subtext of the RFC

raven ridge
#

yes - an April fools joke intended as satire about the HTTP standardization process.

molten onyx
#

it really is ironic isn't it

minor sinew
#

i'll just leave this here

    @tasks.loop(seconds=0.01)
    async def SocketRocket(self, request_man: RequestManager):
unkempt rock
#

ok there's a coin flip discord bot (assuming its written in python)

prolly use a random to generate a number >0.5 tails, <0.5 heads

random uses a mersenne twister PRNG feeding the timestamp

How do you possibly predict the next values

@flat gazelle did a quick search in the channels looks like you know about seeds and PRNG could you possibly help thanks

grave jolt
#

@unkempt rock This is not a help channel, see the channel description. See #❓|how-to-get-help if you want to get help with a question.

feral cedar
#

I mean, the point of a rng is that you can't predict the values

grave jolt
#

you can store the state of the random generator, then generate the next few numbers just to peek, then restore the state of the random generator.

echo harness
#

I guess the person was asking about details of rng implementation

radiant garden
#

Mersenne twister can be broken afaik

grave jolt
#

oh, if you don't have access to the code, it's not possible.

#

anyway, this is off-topic here.

visual harness
#

Quick question, CPython only allocates/frees memory from the OS in big blocks right?

radiant fulcrum
#

thats generally less about Cpython and more about the OS

#

windows i think allocates in nKB chunks

desert peak
#

it's absolutely about CPython, actually.

#

@visual harness I believe that question would be implementation-specific for which operating system's syscalls are being used.

unkempt rock
#

is the Cpython is the "main" python interpeter?

warm galleon
#

@radiant fulcrum would you know by any chance of how to work with cmd sessions with os module?

radiant fulcrum
#

nop

next cliff
#

hi guys im panda i wanted some help in python im just a beginner soo please bare with me

#

hey guys can u please help me with this its a program to count the uppercase lowercase and alphabet and digit in a string

flat gazelle
#

@next cliff hello, this is not the correct channel to ask for help in. Please read #❓|how-to-get-help and use a help channel.

boreal umbra
#

@next cliff lakmatiol is right that this isn't the right channel, but if you open a help channel I'll come find you

next cliff
#

i am sorry

raven ridge
#

is the Cpython is the "main" python interpeter?
@unkempt rock it's the most common one, yes.

spiral willow
#

Most OSes prefer memory requests in bigger chunks then having process a ton amount of memory requests for tiny amount

visual harness
#

That's a relief

raven ridge
#

@spiral willow that's true, but not exactly relevant. See the link I pasted: CPython has its own memory arenas, above and beyond whatever the OS might do. So the answer is unequivocally "yes", regardless of OS.

unkempt rock
#

@unkempt rock it's the most common one, yes.
@raven ridge Is there a difference beetween other ones ( Afaik there is rust one )

raven ridge
#

I don't know of any rust one, but perhaps there is one.

unkempt rock
#

what is the difference

raven ridge
#

I know of CPython, pypy, IronPython, Jython, MicroPython, CircuitPython...

unkempt rock
#

what is pypy?

#

and ironpython

#

and jython?

#

and mcropython

#

and ciruit one?

#

I dont one anyone I only know Cpython and use it

raven ridge
#

pypy - a Python interpreter written in Python with a JIT
ironpython - a Python interpreter that runs in the .net clr
jython - A Python interpreter that runs in the Java JVM
micropython - A minimal Python interpreter designed to run on microcontrollers
circuitpython - a fork of micropython designed to be easier to teach, and to have greater uniformity across different microcontrollers

unkempt rock
#

written in python!?

#

lel

#

and yes

#

why there is lots of things like this

#

I would say "An developer say: Don't repeat yourself." to guido

raven ridge
#

because they work better than CPython in different niches, and because people find them fun to build.

unkempt rock
#

how can I try pypy?

#

and btw

#

why guido didnt made a compiler too?

raven ridge
#

why guido didnt made a compiler too?
@unkempt rock You mean, why does CPython not have a JIT?

unkempt rock
#

JIT?

raven ridge
#

just-in-time compiler. It translates bytecode to machine code at runtime.

unkempt rock
#

I mean why guido didnt made a compiler for Python to compile Python but made lots of unnecessary interpreters

amber nexus
#

Because python was never intended to be a compiled language

raven ridge
#

Guido didn't make any of those interpreters.

#

He made CPython; other people made all the others.

unkempt rock
#

Guido didn't make any of those interpreters.
@raven ridge oh

#

I got it

amber nexus
#

If Cpython had a JIT though that would be pretty cool

unkempt rock
#

soo

#

why people didnt made a compiler too

#

He made CPython; other people made all the others.
^^

raven ridge
#

pypy has a Just In Time compiler, like I said.

unkempt rock
#

so is there a way to stop pypy?

#

and get the machine code

raven ridge
#

Cython (as opposed to CPython) can compile Python code to C code that can be compiled as a CPython extension module... That's the closest thing I can think of to what you're asking about.

#

If Cpython had a JIT though that would be pretty cool
@amber nexus There was some talk about CPython getting a JIT in 3.12 or 3.13 in last week's core dev sprints, from what I've heard. It may come one day.

amber nexus
#

Yeah I heard it was a possibility

raven ridge
#

that may just be aspirational, but it's definitely on the table.

amber nexus
#

I wonder how significant the speed boost would be with a JIT

brave badger
#

I would expect something along the lines of PyPy for pure Python code but is it too much to expect?

#

Nothing wrong in hoping, although if that was the case, I'd be really happy

unkempt rock
#

Cython (as opposed to CPython) can compile Python code to C code that can be compiled as a CPython extension module... That's the closest thing I can think of to what you're asking about.
@raven ridge how can I install / use it

#

btw guys

#

how python import keyword works?

#

where can I find o n l y import's source code

raven ridge
true hollow
#

how python import keyword works?
@unkempt rock it imports a file in the current name space

#

where can I find o n l y import's source code
@unkempt rock surprisingly, there are many files for this single keyword

unkempt rock
#

@unkempt rock surprisingly, there are many files for this single keyword
@true hollow source code != ONE File

#

it can be lots of files

raven ridge
#

it's not even one language.

#

it's written in a mix of Python and C.

unkempt rock
#

it's not even one language.
@raven ridge Cpython

raven ridge
true hollow
#

it's in the:

  • grammar file
  • token file
  • Python/import.c (core)
  • the parser, ast and tokenizer
  • evaluator
unkempt rock
#

oke ty

true hollow
#

still the import.c is quite complex tho

unkempt rock
#

aa wait

true hollow
#

I'm not sure why you'd want to play with the import keyword

unkempt rock
#

isnt __pycache__ storing compiled python files?

#

@raven ridge

amber nexus
#

Compiled to bytecode

#

That bytecode is then interpreted

unkempt rock
#

arfgh

raven ridge
#

right. .pyc files are bytecode, not machine code.

true hollow
#

when you execute them the evaluator is directly called

unkempt rock
#

hahaahahah :|

#

its hard to make real compilers / interpreters

true hollow
#

not really

#

cpython is just a complex case

unkempt rock
#
from sys import argv

file = open(argv[1])

for line in file:
  if line[:5] == "print":
    print([5:])

file.close()
#

haha interpreter

raven ridge
#

Python can do things that cannot be done in languages that compile to machine code at build time, and then just run that machine code at runtime.

#

It's impossible to have a feature like exec without running an interpreter at runtime.

#

or eval for that matter.

unkempt rock
#

cpython is just a complex case
@true hollow I red lua source code too

#

its complex too

amber nexus
#

Well yeah, all major languages are going to be complex

raven ridge
#

the first version of an interpreter is gonna be pretty simple. The longer they live, the more features are added, and the more complex they get.

unkempt rock
#

and yeah a guy said me fork lua its easy to customize

amber nexus
#

I mean you can just edit the language so yeah

#

You have to actually understand what you're doing when customising it so as to not break anything but if you have that knowledge then sure

unkempt rock
#

I need a keyword like #include "" in c

#

import is not good

amber nexus
#

So you're trying to change a language, it make it more like another language

#

That just sounds like quite the rabbit hole that's going to waste a lot of time for little payoff

unkempt rock
#

:P

#

Its for myself actually

#

import is not good
^^

#

I need a keyword like #include in c on python

amber nexus
#

Well goodluck with that

unkempt rock
#

?

#

I wont make something

#

I dont know how to :P

#

import sucks

#

I even cant import another file in another directory

#

like

amber nexus
#

Yes you can

unkempt rock
#

wait Im typing

#
/src
  /foo
    main.py
  /bar
    /spam
      includeMe.py
raven ridge
#

I need a keyword like #include in c on python
@unkempt rock you could literally just run your Python code through a C preprocessor, potentially - though you'd need to avoid # comments that might be recognized as preprocessor commands.

safe hedge
#

What's your point?

unkempt rock
amber nexus
#

You can

safe hedge
#

You can import it but not like that, no

unkempt rock
#

@unkempt rock you could literally just run your Python code through a C preprocessor, potentially - though you'd need to avoid # comments that might be recognized as preprocessor commands.
@raven ridge I mean #include functionilaty

raven ridge
#

so do I.

#

if you ran your code through a C Preprocessor, it'd do the including.

#

that's not a good idea - but it's possible.

safe hedge
#

The ability to import code from any old python file literally already exists

unkempt rock
#

how?

safe hedge
#

It's just you wouldn't do it using import alone

#

There are multiple ways you can do it

unkempt rock
#

from another directory

#
/src
  /foo
    main.py
  /bar
    /spam
      includeMe.py

^^

raven ridge
#

The C preprocessor is a separate phase of compilation that isn't really part of the C compiler, and can be done independently of compiling C code - and there are other languages that are built to use the C preprocessor. Not many, but some.

#

if it's in a package, you can from ..bar.spam import include_me FWIW

unkempt rock
#

bruh

#

..bar.spam

#

its easier in C

safe hedge
#

What.

unkempt rock
#

#include "../bar/spam/includeMe.h"

raven ridge
#

sure. but it does something completely and entirely different, too, so 🤷

safe hedge
unkempt rock
#

and its impossible in interpreters

#

it will break everything if you are interpretering it from other file

#

I always put my program's files to /opt

raven ridge
#

are you trying to get something that behaves like C's #include? Literally pasting in code from another file into a single module?

unkempt rock
#

yes

#

and I'm working on it

#

currently

raven ridge
#

so exec(open("/path/to/file.py").read()) ?

unkempt rock
#

it pastes the whole code to main.py

#

AssemPy loop:

def loop():
  # loop code...
  loop()
true hollow
#

but why

unkempt rock
#

idk lel

raven ridge
#

exec(open(...).read()) is a much closer Python analog to C's #include than import is.

unkempt rock
lyric marsh
#

hi

unkempt rock
#

hi

subtle lion
#

anyone done scareping websites here ?

#

scrapeing*

unkempt rock
#

go get it

#

download it

subtle lion
#

how do you scrape a website that has no homepage ?

unkempt rock
#

go get it
download it

#

nvm Im busy

#

good luck to you

subtle lion
#

o.O

charred pier
#

hello

subtle lion
#

hello

grave jolt
#

@subtle lion This is not a help channel, see #❓|how-to-get-help and claim a help channel if you want to get help.

subtle lion
#

yeah i know had one opened earlier for about an hour. think its a way to advanced question.

#

sakai in the main general might have had an idea. so ill try it later.

grave jolt
#

It's not questions that you find advanced, it's more of a discussion channel. Help channels are fit for questions of any level.

subtle lion
#

ah ye then i missunderstood. 🙂

#

python might be good at aloot of stuff but finding a needle in a haystack might be too difficult yet 🙂 thats more or less the lesson i learned today 🙂

round thicket
#

Is there any place where it's easy to find discussion about a given PEP? There are some PEPs that were proposed that I find interesting that just sort of never happened - and I'd love to hear the original reasons for/against them

visual shadow
#

Usually the pep themselves have a link to the mailing discussions in the foot notes

sacred yew
#

@unkempt rock do you really want to implement #include

#

aka the shittiest "import" system in existence

unkempt rock
#

lol

#

!?

#

python import sucks

grave jolt
#

Are you sure that copying and pasting code from the specified source file into the target file is a better import system than the one implemented in Python?

#

@unkempt rock

#

If you really think so... As it was mentioned before, you can use the C preprocessor.

sacred yew
#

c is awful

#

its literally header copy-paste

#

python import may be bad

#

but c #includes is even worse

flat gazelle
#

doesn't cpp have modules now?

sacred yew
#

and #include is supposed to work with header files

#

but if you're copy pasting the source code

#

that makes it so much more inefficient

flat gazelle
#
$ echo "}" > o
$ echo "{" > c
$ echo "
#include <stdio.h>
int main
()
#include \"c\"
printf(\"Hello World\");
#include \"o\"
">main.c
$ gcc -L. -o main main.c
$ ./main
Hello World
sacred yew
#

personally I think that something like JS imports would be better

flat gazelle
#

yeah, not too fond of python imports

#

they make sense once you understand them, but even then they are a bit unwieldy.

sacred yew
#

import { name, draw, reportArea, reportPerimeter } from './modules/square.js';

#

so much nicer than python

#

don't need to mess with relative imports

#

that break half the time

flat gazelle
#

that doesn't really leave room for things like import hooks, so I am not really in favour of just straight up files. Not sure how to improve it tbh.

sacred yew
#

hm thats a good point

plain spindle
#

what happens if CPython runs out of memory while allocating an exception object?

#

in order to handle it sanely it would have to

#

allocate another exception object overthink

undone hare
#

It will drop the topmost stack objects anyway, so it will have some place to create it

plain spindle
#

ohh nice

glossy wharf
#

hi guys am new to Django can you recommend me a book that cover Django pretty good

unkempt rock
#

im learning c

#

but coming from a python/high level background c is really complicated

#

i mean im really good with python, i kind of know how c works but it still is complicated even for a "expert python programmer"

#

any tips on how to break that wall??

visual shadow
#

Recognize that it's a lower level of abstraction compared to python, so it will be a bit awkward at first. Honestly, my best tip is, ask yourself "how does it actually work" whenever you think of some python code.

#

That may help you prime yourself to thinking in C terms.

night viper
#

are there any examples of open source web projects using celery?

worn lantern
#

Is there a generic typehint suitable for keyfunc argument return values, or is it normal to just leave that as Any?

night viper
#

you mean like a HKT?

smoky cypress
worn lantern
#

@night viper I suppose HKT could be used for this, I'm just surprised there isn't a type like Comparable or Orderable for having __eq__ and __le__ or such defined like Hashable for __hash__

#

Probably I could define my own with ABCMeta tho

night viper
#

yeah like a concept or typeclass. It would be cool but I guess the ship has sailed on the object model for how mixing work. all objects can have eq and le. And tbh typing in Python is documentation only since you don't get any of the std benefits. if you plan to type so much then a compiled language might be nice

worn lantern
#

I'm using typehints just to smooth out development

#

Some of the dependency injection stuff I do would be a struggle to build even in the most modern typed languages I've looked at

#

Anyway, I really don't care about whether a keyfunc returns an int or a tuple or a str, so long as it can be compared to itself, which is the general expectation for keyfuncs anyways. Since they're a python idiom I was surprised to see they're not captured by a type hint prebuilt

vestal ginkgo
#

hello there

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied mute to @vast frigate until 2020-11-02 18:39 (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).

gilded imp
#

Does anyone knows how to import a library and create a function in the same line ? Is it possible in python 3.6 ?

#

something like import math; def f(x): return math.exp(x)

#

Can't find anything

spice pecan
#

that would work, though I don't really see why you'd want that

gilded imp
#

It's syntax error. I'm trying to make my code in one line

spice pecan
#

I guess you could use __import__('module'), look into #esoteric-python for that kind of stuff

desert peak
#

@gilded imp

def f(x): return __import__('math').exp(x)
#

I'm uncertain you could call yourself an expert python programmer and call learning C "really complicated"

I mean, you have to consider memory semantics and new syntax, but it's still just programming.

sacred yew
#

c honestly isn't that complicated

#

the only "extra" things it has is manual memory managment

spark magnet
#

@gilded imp why did you want it all in one line?

gilded imp
#

Im trying the past 3 days to solve a 2kyu kata in codewars. Im 4 and i want to rank up. So its a one line kata

#

I've done with the solution, I now have to short enough my code

#

Of course the function is more complicated than the other above.

spark magnet
#

are there more reasonable katas you can do instead? This is just obscure trivia.

gilded imp
#

There are a lot but I just liked that. It contains math-geometry and I study maths so I chose that.

grave jolt
worthy widget
#

alright

tepid spindle
#

lambda it would hang

#

what are we discussing?

brave badger
#

Not much at this time

sage bear
#

Which book is best for python(beginner)?

boreal umbra
#

@sage bear there are books on our resources page

#

!resources

fallen slateBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

boreal umbra
#

I think "automate the boring stuff" is most often recommended to beginners, but it's not the one I used. This channel is for advanced discussion about the language so stick to #python-discussion for other topics.

tidal marten
#

Nvm, I mixed up isinstance with issubclass

#

Hahaha...

#

Anyhow, do you guys have any tips for mapping __init__ parameters to UI elements? I'm using PyQt5 and I'm trying to initialize classes from GUI.

half wolf
#

Get the signature from the class?

desert hearth
tidal marten
#

Yeah, probably. The problem would be with the more complex (dynamic) parameters. I'll probably just write bridging classes for all of them...

#

Can't you use something like Jupyter Notebook?