#internals-and-peps
1 messages Β· Page 97 of 1
re dunders, i forgot where i read it, but the message was: python devs used dunders so that you dont have to
I believe originally dunders were intended to be used by library creators, not end users
Well, except __init__ and __repr__/__str__, I suppose?
Probably not init, not sure about the other two to be honest
Also comparison operators for priority queues and such
I guess it would be better to have a rich library with ready things you can reuse. Sort of like dataclasses.
Yep
But you'd limit your app quite a lot
I think it is good to have some more meta objects in your app, especially in more complicated ones
Especially in a language as modular as Python
Like you could say that in Java reflection should only be limited to library creators, I think that would be pretty fair
well, dunders aren't about reflection
they're for operator overloading and similar stuff
But they allow the same kind of meta programming
I guess they are used for simpler stuff yeah
Yeaaah
The reflection API is somewhat scattered across dunders, inspect and some other modules.
So dunder methods are for overloading.
That was a poor example
And dunder attributes are mostly for reflection
is reflection implementation specific or standard?
"standard" in inverted commas of course π
I guess that some parts are standard, some are not? Mostly standard, I suppose. But then, pretty much nobody is using anything besides CPython and PyPy
There are some 'optional' parts of reflection, like inspecting stack frames.
huh. https://docs.python.org/3/library/inspect.html#inspect.currentframe
CPython implementation detail: This function relies on Python stack frame support in the interpreter, which isnβt guaranteed to exist in all implementations of Python. If running in an implementation without Python stack frame support this function returns
None.
I didn't know that wasn't required. Interesting.
well, if your implementation is stackless, that might not work π
indeed, indeed.
the most commonly introspected things are function/class names, docstrings, and annotations, I would think
seems like people use the terms introspection and reflection interchangably
is that an accurate statement? "nobody is using anything besides CPython and PyPy"?
Not completely nobody but I think you'd probably have a hard time finding someone using a different implementations apart from the two mentioned above and circuit/micro python
Jython and IronPython are horribly outdated.
of course my implementation will be the newest when it is released! π
ironpython3 is being worked on I think but I've no idea on the progress being done there
unfortunately https://www.jetbrains.com/lp/python-developers-survey-2020/ doesn't mention implementations
if Python had an ISO Standard CPython would become less important.
@peak spoke And then Python 4 comes out right before release π
BTW, what's that new stuff from MyPy, which is basically compiled python?
I don't think that'd fit very well with the yearly release schedule
And I've heard a lot about Nuitka and Cython, but I don't really know how popular they are in practice.
I think cython is used fairly often
Cython is used alot for any C based lib
because it makes binding to C/C++ libs and wrappers so much easier than doing it raw
Nuitka is fairly popular but lesser than Cython just because in the real world you dont use Python to make exe apps, its generally used more with it's ability to run code through a optimizing compiler that can make the code considerably quicker providing most of your stuff is numerical
oh no not a committee
It's not used often but it's not that uncommon to use python for an exe because of the development simplicity - for example I'd much rather use the python Qt bindings than doing it in C++ for majority of its uses. But pyinstaller is used much more for it as its design is a fair bit simpler and has a higher chance of running right away
Cython and Nuikta are common as mentioned
More so than PyPy in my experience
Cython for sure is way more common than PyPy
Nuikta is less so because new but more are using it nowadays because it's nice
Isn't nuitka based on CPython? Or does it have its own runtime from scratch?
I would say beside those implementations the major ones are MicroPython and RustPython.
CircuitPython is a fork of MicroPython that's pretty heavily used as well, in a certain space.
There is also a forky but not so forky version of MicroPython called pycopy which implements a subset of Python and also actively developed (by its author)
I haven't been a fan of pycopy's author's approach on Python-Ideas.
Me too
though I just unsubscribed from python-ideas last month
it became a list where people repeat themselves all the time or propose really esoteric stuff. I just wait them to pass to python-dev and comment there
Wouldn't really worry about micropython or circuitpython, basically neither of them are used by anyone except hobbyists
Cython etc at least have major use in scientific computing
though we are talking about 'implementations'
my rough guess: >99% CPython, of the rest, >99% PyPy
seems about right
Accurate
RustPython has a chance to become another contender simply because of it's ability to compile to WASM which might be something people want to try out with, equally the JIT system is a interesting setup
but RustPython is still in very early development
Apropos of nothing but fascinating.
I run my blog on a shared host, with software I wrote myself in Python. It runs fine except for a strange lag after startup when opening the list of most recently edited posts. At first I thought this was an unoptimized database query, but various attempts to optimize it yielded nothing. The database is not MySQL, but SQLite, which lives in a file that's in the same directory as the blog software. Eventually I realized since this is shared hosting, it's probably not sparing very much memory at app startup to read-cache the DB file, and so the query is forcing a bunch of stuff to be paged in incrementally in an inefficient way. So I wrote a little routine at startup to just read the entire file so it would be hot in the I/O cache for the server.
The problem went away.
lol
@uncut sage Maybe just read the entire database into memory? SQLite supports in-memory databases.
Although I suppose you need to write stuff as well. But maybe in that case you can update your cache.
Well, this hacko de hack seems to have solved the issue for this particular host. I'd rather not get too clever for my own good.
any type theory expers here?
Is this about Python?
not directly.
better to just ask
would you consider a 1-tuple and an ordinary value type to be equivalent?
for example, (1,) == 1?
I am not talking about Python's interpretation but more generally
this might be the kind of question where languages differ.
no, my question is concerning type theory
Well, they are isomorphic, of course. I don't know any other language that has a 1-tuple.
you can create a 1-tuple in C++ as well - and you can't pass it to a function that expects an ordinary value.
so, no - I'd say a 1-tuple of a particular value type is not equivalent to that value type.
I am not asking how different languages' tuple abstractions; I am asking in the context of type theory
Given that a tuple has its own methods, I don't see how you can argue that it's not a distinct type.
from a Liskov PoV, the things that you can do with a 1-tuple-of-ints aren't the same as the things you can do with an int.
note I ask if they are "equivalent"; i.e. it always makes sense to be able to directly assign one to the other
not from a language perspective
but from a type theory perspective
it definitely doesn't. It would be extremely surprising to me if you were allowed to pass a 1-tuple-of-int to a function that expects an int.
again you are thinking in terms of programming language abstractions
I am asking about type theory-level abstractions
i'm not sure what the point is of type theory if it doesn't describe how programming languages work.
let me put it another way: how would an "int" and a 1-tuple of an "int" behave differently
a 1-tuple-of-int has a length, an int doesn't.
that's what I meant from the Liskov side of things. You can pass a 1-tuple to a function that expects some type of iterable sequence; you can't do that with an int.
there aren't many operations they share.
maybe only the ones they both get from object.
as a result of this conversation neos now has a new feature: type elaboration
the type target_list is elaborated from language.type to language.type.tuple if a comma token is detected
well this is transmutation disguised as elaboration
so language.type.tuple can be a tuple of assignment targets?
corrected:
"target" is just an artefact of the schema
I am transmuting the type of target_list not target
target is defined separately to the "tokens:" thing
hmm but in a,b,c = 1,2,3, there are sort of two kinds of tuples at work.
since im reading that neos is mainly for neoGFX, would it not be way easier to write a neoGFX api in c++ that you can then link to from any language? and just use that respective languages runtime.
language.type.tuple is only a tuple in the most general language agnostic (type theory) sense which will be used during semantic concept folding
@pliant tusk you mean create bindings?
yea like most applications that allow scripting like this do
I prefer the scripting engine approach rather than bindings.
someone can always create bindings if they have the time
but why would you reinvent the wheel?
besides I will be creating neoGFX bindings that neos will be calling into
surely you know there is only one answer to that question?
and what is that
NIH of course
what is NIH?
Not. Invented. Here.
"Not Invented Here", usually used as a label for a foolish isolationism.
ah ok
"we don't trust anyone else to do it well"
that seems like a flawed sentiment
if people didn't revinvent wheels there would only be one brand of computer, one operating system, one programming language. people and companies reinvent wheels all the time: nothing wrong with it.
it's usually used to point out a flawed sentiment, yes.
When someone says that something is "NIH", it's not a compliment.
they mean that they reinvented something existing just for the sake of reinventing it, not because of any particular weakness or flaw in the existing implementations.
@weary garden then why not build a new CPU for neos? or better yet redefine computing to not use CPUs?
when I use the term NIH I use it because I am creating something that I consider to be better than the competition or received wisdom
you believe that you can personally reimplement python (and several other languages) better than people who have been working on the platform for years?
you may want to stop using "NIH" for that. You're definitely misusing it; the term has a definite negative connotation.
Time to create a new abbreviation π
@pliant tusk that isn't what I am doing; I am not really reimplementing Python: I am creating a universal compiler and Python will simply be one of the many input schemas you could give it so it can compile Python programs. So it would be more accurate to compare what I am doing with other attempts in this space (such as LLVM, GraalVM etc)
i feel that even if you are successful at that monumental task, it is practically impossible to do effectively. You will lose every language specific optimization.
disagree.
@weary garden you are implementing python, and you do believe you will do a better job than existing implementations. right?
let's just wait for the Python implementation and see. I don't think these discussions here are very productive
I am implementing a universal compiler and Python will be the first language schema I will create
and you think it will outperform existing implementations. Right?
yes
but as I don't want to get booted from this server I am not going to repeat why I think that is the case.
wise π
to clarify, you expect neos to out perform all the language schemas you plan to implement
no, I expect neos Python implementation to be faster then PyPy and by implication CPython.
Leigh has been talking about this for a long time. We have to let him be and implement it.
fair enough. @weary garden let me know when you have a working alpha, id love to test it out
thanks π
pypy is faster than CPython at running stuff that doesn't need to be fast, and slower at running stuff that does, unfortunately.
It's a common optimization for Python libraries to move performance-sensitive portions into C extension modules, where they have less overhead. pypy can use those C extension modules, but has massive overhead in emulating CPython's C API
so - it's faster than CPython at running the libraries that no one ever bothered to optimize, but slower than CPython at running the things that someone already bothered to optimize and speed up.
But in theory, if someone made PyPy-happy bindings, it would be faster in that regard, right?
E.g. what if Cython could make PyPy-happy bindings?
Can you write extensions for PyPy that don't have to rely on some overhead that simulates reference counting?
pypy doesn't have its own C API, AFAIK
... since there's no C π
ah rightht
well, it's own c-compatible ABI, anyway. That doesn't require C, but it still doesn't have one.
https://stackoverflow.com/questions/66512731/how-to-get-certain-pygame-modules-to-work-in-vsc-other-fixes-not-working can someone help me with my pygame module issue. or take a glance at. if theres any pros in here
is this the right place to help me configure my command line to work with new python version. installed ubuntu and it had 3.8 and i downloaded 3.9 but the "python3" command used 3.8. i have to do "python3.9" if i want it to use versiin 3.9. thanks for the help
add the directory with the new python download to the Environment?
idk ubuntu, but i had a similar issue where i went into system settings in windows and had to enter certain directories in the environment to get certain things to work in my commant prompt
Is there a known way to get answers in google forms?
What do you mean by 'get answers'? Google Forms is just a form that collects information π
if you mean to get response data, yes you can with the google api*
*only for forms you own
\o/
Is it somehow possible to make lambdas and closures in general serializable by pickle?
Is using partial on a top-level function the best/only way?
got a quick question regarding web scraping (being kinda new to that). How do you write a code in a way that it notifies you when the current page or summary of that page (that you have scraped) has been edited or changed ? and should python scrap that page continues with an intervals (to check for changes) or is there a smart way to get around that ?
hm.
I just did some reading about this stuff
don't have an answer, but I learnt something new
this question doesn't sit well for this room, though im not quite sure where to direct it to be honest with you. perhaps try python general. As for this room, check the description
Why python lacks inline try-except?
Something like lambda x: try 1/x except ZerodivisionError math.inf or lambda x: try 1/x else math.inf
Hm, apparently that was already proposed and I'm not happy it was rejected
https://www.python.org/dev/peps/pep-0463/
as an alternative, remember that you can always make a function out of something like that
added bonus: it helps you put a nice "name" on top of the operation you wanted to express
Well, both lambdas and ternaries can be replaced by functions, but they are still useful.
yeah i cannot give any further insights besides what's already stated in that rejection notice
what do you think of Python style ternaries vs C style ternaries
specifically, the order of the operands
I like having the options at the ends, but python's are probably a bit harder to quickly read because of the keywords instead of single punctuation chars
The englishness of python can make it verbose sometimes, ternaries are a good example
I also think sometimes pythons tab style screws it over sometimes too
the inversion of the operands compared to C-style definitely takes a bit to get used to
once you're used to it, it's not that bad
C's use of colon in the ternary makes no sense.
a colon connects a thing to the thing it introduces.
Oh yeah, I've never found C's ternary to be intuitive at all
i think i like the order of C style ternary, though perhaps i just dislike ternaries in general
but yeah, the syntax of the C style ternary just feels meh
as for python ternary, i find myself always having to re-read a line with a ternary in it, because i initially just see an expression and expect that's being set
but its honestly not too too bad, because it's still nice to read
very english like
syntax aside
like just the operand order
Python is the only language I know that has it this way
i think this is one of those things that depends on which you used first.
because in english we use both forms.
"get some milk if they have some, otherwise heavy cream"
"if they have milk, get it, or heavy cream will do"
c-style matches the flow of a normal if statement though
Python ternaries made immediate sense to me the first time I saw one. I find C-style ternaries confusing.
c = (a < b) ? a : b;, like, what does that question mark or colon mean?
Scala and Haskell use Python syntax but C order
change all your tabs to spaces
also, this isn't the right channel, check out #βο½how-to-get-help @unkempt rock
thanks
I think I find if condition then expr else expr easiest to parse.
disagree: there are lots of contexts where a colon is used as a delineator
e.g. IPv6 addresses
to be fair, Python uses the colon for slices. I don't know of another place that uses colons for alternatives.
I like the C order.
The notation? I think it's fine. It's just two characters, so I don't think it's any more cryptic than any other operator like % or & or !=
I actually like ?: in JS/TS
return foofoofoofoo
? barbarbarbar
: bazbazbazbaz
? fizzfizzfizzfizz
: buzzbuzzbuzzbuzz
even something like this
but that's maybe too much
For that I generally prefer the haskell language extension which allows
if | cond = v
| cond'=v's
Is there a syntax form for which there isn't a haskell language extension?
Or the hostname and the port: 127.0.0.1:8000
Or the scores in sports: 1:5
Or namespaces in C++ and Rust: std::string (although it's a double colon)
Also, path variables in Bash are paths separated by :s
I think the same applies to any new operator. +-*/ don't explain themselves naturally, neither to %&|^, and neither do English-based return, yield etc. So one you know the meaning, it's not that confusing.
Although putting the ? before the conditional might make it easier to parse. So maybe if c then t else e is better overall.
I mean, all symbols are fundamentally arbitrary, but the other operators you mentioned have established meanings in math or computation, and return and yield are appropriate keywords given their meanings in English.
I feel like with the question mark for ternaries, they were just like "welp we haven't used that ascii character for anything yet, and conditions are kind of like questions, I guess?"
trigraphs use ? :P
I don't think knowing what return or yield mean will give you insight into their semantics in Python
(judging by questions asked on the server)
or something like class
If you replace class with ducky, I don't think it will be less confusing to a native English speaker
there's a point at which the phenomena that return or yield are intended to capture have no analogue outside of programming
you are definitely wrong there π
well, how does the colloquial meaning of class match OO classes?
seeing the word "class" doesn't instill the reader with knowledge of OOP, but it at least uses a word that is consistently used to describe the functionality that that key word gives you.
well, yes
I mean, if classes were named duckies in other languages
@dataducky
ducky Point:
x: int
y: int
aren't we just talking about how language is fundamentally arbitrary now?
Language is fundamentally arbitrary π₯ π₯³
"class" definitely means something that "ducky" does not.
You define a ducky, and you can call it to create ducklings.
good luck with your new programming language π
Well, maybe it means something in the context of mathematics.
for people outside of programming/math/formal logic, I think most people think of "class" as meaning what "course" or "section" mean in academia.
there is a point where operators get too many, regardless oh how well reasoned they may be Aβ{ββΊ+.5-β΅}β. Where people like their operator ratio is very much personal opinion.
@boreal umbra what do they think "S-Class" means? https://www.mbusa.com/en/vehicles/class/s-class/sedan
well, category or blueprint or template would also be a fine name which wouldn't expose any more or less about what a class actually is
names tend to be easier to memorize than operators, but they are also quite arbitrary and seldom is there a descriptive yet short name for a thing
blueprint might actually explain a bit more
since the thing tends to be more complex than a single word holds
it sounds like a marketing term that doesn't necessarily mean anything. but there weren't very many years of my adult life before I started to learn programming so I'm not sure how many unrelated senses of the word "class" most US adults have in their vocabulary.
"First-class mail"?
class does mean category even for non programmers
one of the well-known meanings of "class" is a category of things
fair enough
does that mean that the name would be short for category, cat?
operators aren't really less descriptive than names a lot of the time. <: does leave a rough hint of what it means especially given some context of a surrounding program
I am not arguing for replacing class with |_| anytime soon, but I will also not argue for replacing : with do nor + with plus
one example of a needless word might be template in C++, I suppose?
could've been just <...> after the class/function name
like in Java/C#
template makes it very easy to find what the syntax means, which is a problem with a lot of new features.
like, good luck figuring out what does <<x>> in raku do
doesn't template have some other purpose other than declaring templates
not actually what I meant, but that one is on me for picking something ambiguous
not that I can recall...
I think google has improved on its non-letter search lately tho
ye, and things like hoogle and the raku search are becoming more standard
but I sometimes see people ask what % or something like that because they're not sure for what to search
ye, it is a tradeoff
maybe it would be useful to create a simple page that maps non-letter operators to their names
(for Python)
And symbols being reused for multiple things doesn't help. % in Python is modulus or legacy string formatting, for instance.
I find python is about right in the operators.
yeah
I would prefer custom operators over overloading most of the time though
but custom is much easier to create abominations with
but granted, it's not used anymore, apart from... half of the tutorials 
and the logging module
C++'s std::cin >> x is a perfect example of the sort of abuse of operator overloading that every book tells you not to do.
Still doable with overloading π <#esoteric-python message>
I still use it when I can't use f-strings. And it's still used in some DB-API interfaces that use format as the paramstyle - https://www.python.org/dev/peps/pep-0249/#paramstyle
although yes, custom operators allow for just a higher degree, higher plane of abomination
https://jaspervdj.be/posts/2020-03-12-visual-arrow-syntax.html
I still use it when I can't use f-strings.
Why notformat?
when putting values into json in string literals, format is no nicer
I don't think I understand what you mean
"""
{
"key": 34,
"more": {
"nested": {
"keys": [%d]
}
}
}
"""
``` trying to do this with .format would be annoying
ah you mean % is nicer
but, well, this approach is not very sustainable, because you'll get into escaping issues and such... so maybe just use json.dumps?
we don't have lens
can't really create a setter into a nested structure in a nonpainful way
well, you can mutate it π
then you have to deepcopy everytime and its a whole mess
this is easier for small scripts
maybe yes
for large projects, you would probably want to use something safer
I mean, there are lens libraries
Although I don't think they work with something like immutables.Map. But making a lens library from scratch is not very complicated tbh.
but that's not something you would do for a short script
I would probably just write a bfs that would just look for ... in the literal and replace them in order
There are tables with that in docs. One of the examples is https://docs.python.org/3/reference/expressions.html#operator-precedence (and remainder has a footnote about it being used for string formatting as well)
oh right, thanks
that's a useful link
although it still doesn't mention things like decorators, but
.format is slower, and I dislike its placeholders compared to the old ones that I'm more comfortable with.
in fact, .format is pretty much the only string formatting option that I never use.
I used to code for python3.4 because that was what my target system had (and we aren't supposed to install anything in there ourselves because official support can deny help... Yay), so I use a lot of str.format, even though it was eventually changed to 3.6 in that system
I like .format because I can prepare the string beforehand and then fill it in with stuff. Usually with 1 thing.
If I fill it in with more things that can be in different order, I use named {}s and use .format_map ^^
But, well, my scripts usually don't need to be fast or anything, just easily customizable to what client needs. So we can with little modification use it for clients with similar needs. So no hardcoded magic values - I use the most general thing and just format it.
You can do all of that with % formatting as well.
!e ```py
s = "%(greeting)s, %(name)s!"
args = {"greeting": "Hi", "name": "Nicky"}
print(s % args)
@raven ridge :white_check_mark: Your eval job has completed with return code 0.
Hi, Nicky!
hello
hello
sometimes the config I do is configured with the client (they usually don't change things themselves even though I document config files and tell them that e.g. they can change the notification text etc...) and just {name} seems to look nicer than %(name)s and has less chance of making a mistake when typing...
and some things I do are done with jinja (email templates, those are not to be used by clients but some scripts have customisable stuff in config files that is later inserted in the jinja template) which uses {{}}s, so {}s are more visually consistent
Those all sound like things that are just a matter of preference - which is fine, we can have different preferences.
write bigger projects. have you made decorators with arguments?
yeah
not only that i made corators with *args and **args that also use yield!
a python super function!
what's the largest project you;ve made?
wanna see my porngithub? can we share here?
the largest project isn't in python, but in verilog
i'm wondering about python projects.
but my largest python project was prolly NLP detecting languages
any language
from a given text
pretty simply using cosine similarity measurement
to laymen it's some rocket surgery
i want to understand something
i wanna know how matplotlib the code base works,
like their design pattern
matplotllib uses **kwargs in every method and i know how it's used, but how are these kwargs passed in matplotlib library
what sort of design patterns are they using
you can get the source and read it
I only use it when I need to do delayed formatting. Cool fact, you can format a fstring to be formattable with {{}}
f"f-string with a {{delayed_format}} {1}"
you don't sound like you do
parsed my first Python program \o/
!ot is the place
Off-topic channels
There are three off-topic channels:
β’ #ot0-psvmβs-eternal-disapproval
β’ #ot1-perplexing-regexing
β’ #ot2-never-nesterβs-nightmare
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
gods are off topic
why is it printing the strings backwards?
but god's advanced fam
because of the way folding works
@coral drift please keep on topic
kk god.py
which channel fam, there are too many
!ot one of the off topic ones
Off-topic channels
There are three off-topic channels:
β’ #ot0-psvmβs-eternal-disapproval
β’ #ot1-perplexing-regexing
β’ #ot2-never-nesterβs-nightmare
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
mixing the hint and expression looks a bit weird to me
what are good packages for sublime text?
I wish sublime text supported RJSON
@leaden gorge you could ask in #editors-ides
If you need to support Python < 3.9, list[int]() isn't an option
It?
I prefer the more verbose one with the separate hint, but that may just be because I've seen it more often. Outside of backwards compatibility, I'm not sure I have a strong preference.
it would be neat if the type was inferred
i made a software
that detects political ideology sentiment from religious books
where can i share my results
and howcan i know if if code is doing the right suff
that'd be on topic in #data-science-and-ml
I am having problems finding function calls in the grammar...
Isn't it, primary: primary '(' [arguments] ')' ?
but I cannot find where primary is used
power: await_primary; await_primary: primary
Let the sunshine, let the sunshine in.
I wonder which properties of python make it hard to compile to binary.
Is it possible to have a compilable subset of Python that runs on CPython and allows to write non-trivial programs?
I'm aware of stuff like Cython (which is, apparently, a dialect, not a subset) and stuff like Nuitka, but not very knowledgeable in that area beyond "few people use it, it must mean there are some issues"
Yeah, browsed through mypyc and various monkeypatching seems not to play well with compilers.
not just not a subset - Cython is a superset
Well, I haven't done Cython dev, but apparently you can't run Cython code in CPython and vice-versa, due to the use of Cython-specific datatypes.
you can't run Cython code at all - Cython code must be transpiled and then compiled.
Once it's compiled, you can import it into CPython as an extension module.
Fair point, but can you take a pure python library and turn it in extension module without re-writing it? Or take a source code of Cython extension and import it as a module?
Fair point, but can you take a pure python library and turn it in extension module without re-writing it?
Yes - Cython supports a superset of Python; all valid Python code is also valid Cython code (with very few exceptions)
Or take a source code of Cython extension and import it as a module?
Generally, no - Cython is a superset of Python; Python can only execute the Python subset of Cython's language
Thanks! TIL, i didn't know about "all valid Python code is also valid Cython code"
It's not that it's hard to compile to a binary - it's that it wouldn't be any faster if it were compiled. The slow part is all of the dynamic type checking that needs to be performed. You can compile any Python code by transpiling it to C using Cython, but it's not any faster to do that, because Cython needs to generate C code that does exactly the same work as CPython needs to do - and it's that work that's expensive.
can you rename a function
i want to do something like this
read a line form a file, which has a list of words say
a
b
c
...
thne i want to make fncitons dynamically
def a:
pass
def b:
pass
htf will i do that?
Well, yes its possible, should you do it? Probably not
But you can use something like exec to perform code generation but its a little on funky side
i wanna do da funky
i need it to show my intellect
and superiority and use bzzwords like cyberquantocryptography
@unkempt rock Then #esoteric-python is your destination of choice
i thought it's some advanced shit
This channel is for discussing the Python language itself, mostly its future and past, its implementation and all that other meta-stuff.
Which is better for image classification PyTorch or Tensorflow?
try #data-science-and-ml. this channel is for language discussion.
The first option for both. Constructing a set or list is idiomatic using literals imo.
Mypyc looks most promissing to me. You can lock down types heavily on a subset/core of a program using mypy --strict mode and get a 10x speed up. Especially on algorithmic code. And it will still run fine using cpython if you want.
Unfortunately the development pace of it looks quite slow.
It seems like a first official release is in the works, there is now a readthhedocs page https://mypyc.readthedocs.io/en/latest/index.html
but set() isn't a literal, it's already a function call
A set literal would be... {*()}, I suppose?
Uh true my brain processes it as literal. I guess because the additional getitem call has a runtime cost. Though its probably negligeable.
but yeah, I've never seen list[int]() (maybe because it's only supported since 3.9? probably)
If you want absolutely blazing fast performance (whole 3 ns), {*()} is the way
although that's probably noise
It's meant for type hints
wdym?
It didn't occur to me that we could now do x = set[int]() although then it won't make it into __annotations__
list[int] is a type hint for a list with ints in it
well, yeah, I guess list[int]() is sort of an abuse...
This is by far the fastest, not sure there's a better way
~/Documents/pydis >>> mypy lint.py
lint.py:1: error: "list" is not subscriptable, use "typing.List" instead
lint.py:1: error: "list" is not subscriptable
lint.py:1: error: Incompatible types in assignment (expression has type "List[float]", variable has type "List[int]")
Found 3 errors in 1 file (checked 1 source file)```
odd, mypy says list is not subscriptable, but it does recognise subscripted lists.
are you sure you're on 3.9?
no, same thing
Hacks π
Probably you need mypy master build or something
Mypy always lags a bit behind
Thanks!
BTW, is anyone slightly bothered that return a, b, c syntax produces a tuple while stuff like *args produces list, even if you rarely mutate it?
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
(1, 2, 3)
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
1 [2, 3]
hm, weird
If I run with 3.10 specified it does allow subscripting list
Yeah, had a brain fart and mixed it up in my head.
Behold, a whopping 40 nanoseconds saving!
Basically, the LOAD_CONST 1 and SET_UPDATE 1 are unpacking an empty tuple into a set. Which is a no-op.
so I just removed that operation.
So if Python had macros that were translated directly into bytecode, this would be set!
or {,} or similar syntax
It's because of the implementation (I believe). Basically, in an expression like a, b, *rest, c, d = iterable, Python will first consume two items for a and b and then put the remaining items in a list. Then it starts at the other end and pops two items for d and c. What remains after popping is the list for rest. This is easier to do using a list with defined pop behaviour I guess.
Well, it's happening in C code, and it generally doesn't matter whether you're appending to a list or a tuple there, right?
Ah, I see
I think that because they're creating a mutable structure to pop items from, they've picked a list instead of a tuple
but, I'm not entirely sure. That part of the reasoning isn't documented in the pep.
The tuple would take more memory than needed if you have items that you will remove from the end
Hello. Sorry if I misuse this channel, first time posting here.
Why do we bother working with .env files and environment variables (with dotenv) instead of just working with a env.py and from env import foo? Is .env more secure? Or because it's more flexible for different environments (e.g. in a docker container) etc.?
What typically happens is that .env is ignored by version control and the actual sensitive data is read in some different way in different environments.
You may have different tokens locally than you do in a staging deployment or production environment
Sometimes it will also be easier to use environment variables in production rather than .env files, depending on your setup
Docker also has a separate secrets system and kubernetes has yet another way of providing secrets to containers
Docker also has a separate secrets system
Do they? I never seen a secret store within Docker, that's interesting
To give you an example, in @fallen slate's project we ignore .env in .gitignore, which means that developers can insert their Discord API token locally without it accidentally getting committed into the git history.
I totally understand. Thanks.
Here's a blog post about it: https://www.docker.com/blog/docker-secrets-management/
Nice, cheers
But maybe adding a config.py or variables.py to .gitignore and working with them would also do the job, right? E.g. I just want to keep a variable VERBOSE and if it's true, I want to display some additional outputs. I just want to avoid a bad practice.
Why use a py file and not a plain config file?
You might be tempted to add more stuff into the py file if you don't employ some set of strict rules.
Just because it's easier. Do you mean like an ini file?
well, json might be easier to work with (also has a standard library implementation)
what our bot https://github.com/python-discord/bot does is keep a 'template config' in git, but you have to copy it and modify locally under a name which is ignored
I used to work with them. But one of my coworker started a trend like just using config.py and then I started to question it.
I see, thanks for advice π
the issue is that you might be tempted to start doing stuff like complex decisions, loops, recursion, I/O including networking...
There is a config language called Dhall that allows making a config with functions and types in a restricted manner with the guarantees that a) they will always terminated; b) it won't do arbitrary I/O. But I guess that if you propose using it in a Python project, people will look weird at you π
but if you just need a toggle, use a plain json
or an environment variable, as suggested
or a commandline argument, if that makes sense in the context
Okay, thanks. It was a little bit ugly to read (sometimes) couple of json files files right after imports, so just importing variables seemed cleaner π
I think configuring using .py files is fine if it fits your needs, usually for sanity you will have the external attributes loaded into some kind of an instance at runtime anyway, and use annotations to get autocomplete
Unless you have extra logic there populating this instance e.g. from various files depending on environment, or merging information from multiple files, I feel like it's fine to just put the value in the .py file π€·ββοΈ
Okay, thank you so much.
Hey, just a generic question about DRF. When overriding methods (create, update, etc.), is it better practice to do it on the View or the Serializer?
hmm, anyone up for discussing creating a PEP for annotated assertions in the language (aka making pytest assertion rewrite unnecessary)
what do you mean by annotated assertions?
(not that I'm qualified to write a PEP, just curious π )
basically when there is a assert with a expression, remember all intermediate values
so assert foo.bar() == expected.yolo records foo, foo.bar, foo.bar(), expected and expected.yolo and ships enough detail to figure issues with the expression
so like a recorded pdb debugging session?
thats one way of saying it
right now pytest does ast transformations to implement this
and it really should be part of the language
so essentially assert should do something like a lisp quote, but also keep all the values.
yeah, a macro or something
What's the issue (if any) with the ast transformations?
I suppose that it's not the most straightforward thing...
although, where would it be useful besides assertions?
its expensive, and hard to integrate with site-packages ^^
the feature i intent is specifically for assertions
And I guess unittest just does it's own assert functions so it wouldn't benefit from this. Am I correct in saying that?
Are there other testing packages that are in use that also rely on asserts directly? Trying to think towards a good groundwork for a pep
so the semantics would be somewhere like
super_assert foo.bar() == expected.yolo
``` >>> ```py
__record = __make_record()
try:
__0 = foo
__record("foo", __0)
__1 = __0.bar
__record("foo.bar", __1)
__2 = __1()
__record("foo.bar()", __2)
__3 = expected
__record("expected", __3)
__4 = __3.yolo
__record("expected.yolo", __4)
__5 = __2 == __4
__record("foo.bar() == expected.yolo", __5)
except BaseException as e:
__record.exception(e)
else:
if __5:
__record.succeed()
else:
__record.fail()
```?
I can see how it becomes more complicated...
super_assert foo.bar() == fizz() == buzz()
``` >>> ```py
__record = __make_record()
try:
__0 = foo
__record("foo", __0)
__1 = __0.bar
__record("foo.bar", __1)
__2 = __1()
__record("foo.bar()", __2)
__3 = fizz
__record("fizz", __3)
__4 = __3()
__record("fizz()", __4)
__5 = __2 == __4
__record("foo.bar() == fizz()", __5)
if not __5:
__record.fail()
else:
__6 = buzz
__record("buzz", __6)
__7 = __6()
__record("buzz()", __6)
__8 = __4 == __7
__record("fizz() == buzz()", __8)
except BaseException as e:
__record.exception(e)
else:
if __8:
__record.succeed()
else:
__record.fail()
What's actually called with ()? I thought I was being clever and overwrite tuple's __new__ but it doesn't work if parenthesises are used
literals will be created through direct bytecode instructions or constants created when it's compiled
a zero length tuple like () will always become a constant afaik
and all other bytecodes that create a tuple use the direct PyTuple_* functions. To modify those functions you need to do things involving assemby *at runtime
anyone have any tips on how i can compile my .py file into an exe while keeping the executable as small as possible without py2exe, pyinstaller or pyarmor?
why don't you want to use those tools? Also, why do you want an exe, and why is size important?
im trying to explore new methods so i can try to hide my source code better
if you don't mind me asking, why do you want to hide your source code?
it has an api and a webhook and the last thing i need is either one getting messed with since the file i wish to compress into an executable is going to be public
but if i wanted to mess with it, i would just monitor the network traffic. no matter how obfuscated you made the code, I can watch what you send and receive.
the community im going to be sending this file in will know where to look for simple things in an exe file but sofisticated things like that wont cross their mind which is why im looking for a simple obfuscation method other than the ones i listed
I don't understand how code obsfuscation will secure a web API
Security by obscurity is not security
Or why Python is your first choice for a program that is a compiled binary
@unkempt rock i guess i would start with one of those existing tools, and tweak it to be unusual.
Something something sun tzu underestimating the enemy
any ideas on how i can keep it bellow 4MB? the source is 20kb
i don't know what goes into one of those tools, so I'm not sure whats taking the space, or what you can do about it.
As much as I love python this is a poor use case for the language
i'm sure those tools have done what they could to keep it small.
Have you considered GoLang?
@unkempt rock 5Mb isn't a big deal these days usually
ill explore my options with the methods i know, thanks for the help @spark magnet
#Python tip: Ways to call methods on integers without tokenizing as a float:
23 .bit_length() # space after the digits
5
(23).bit_length() # parens
5
x=23; x.bit_length() # variable
5
getattr(23, 'bit_length')() # the hard way ;-)
5
Uhhhhhhhh
!e Yikes, okay
print(23 . bit_length())
@brave badger :white_check_mark: Your eval job has completed with return code 0.
5
eyes twitch
I means that you can write Java in Python (just kidding):
railroad_ink = (
BoardGame.get_builder()
.add_genre("puzzle game")
.add_number_of_players("1-6")
.add_name("Railroad Ink - Blazing Red Edition")
.build()
)
Hey guys, our teams implement a decentralized access control system and a traceable, privacy-preserving data grid. You can run ML algorithms remotely using data you cannot see. https://github.com/ownership-labs/DataToken https://github.com/ownership-labs/Compute-to-Data
Our vision is to make the hierarchical data flows more transparent. The SDK leverages the trusted features of blockchains to return data ownership to its owners while maintaining the computability of data.
If you are interested, welcome to support our project.
@cold rapids That's not really related to this channel, but it's there to support dynamic sized arrays.
@wide shuttle You're joking, but that's the exact pattern I've seeen in Pyspark.
i was more joking about calling something "Java-esque". Python and Java are, in some ways, fairly different languages and some people will criticise the use in Python of patterns commonly used in Java "because it's like Java". While design patterns may sometimes be tightly coupled to a language an its limitations (like a singleton pattern in Java in order to create some kind of top-level shared data), I think it's typically good to keep an open mind and learn from patterns in other languages.
At the same time, there are sometimes better alternatives in language B that mean that copying the exact pattern from language A does not make a whole of sense (and maybe betrays that the author is more familiar with language A than the language they're currently writing in)
builders can generally be emplaced by factory methods with keyword arguments in python, so that is one example where it isn't too useful (unless some things need more complex arguments and you don't want to have complex dependencies between args or a million tuples)
That reminds me - aren't keyword arguments and factory method a thing in Java too?
I don't think so, no.
I find that Python has a lot of features lessening the need in traditional Java-like patterns.
Types as objects simplify abstract factories.
Free functions simplify strategies and replace one-method objects (though I still prefer callable object to a closure)
Duck typing instead of interfaces. It even works on modules and classes, not instances only.
getattr dunder makes proxies/facades less verbose, and duck typing makes them even less needed.
Traits via multiple inheritance as alternative to composition.
What are, in your opinion, Python-specific patterns that can be solved by another language's features?
def fun(x, y=None):
if y is None:
x, y = x
```argument parsing like this can be solved with multiple dispatch (but there are cases where the python approach works out better).
Fully custom operators allow replacing things like .iloc vs .loc vs [], and can make things like parser libraries cleaner as well
there are probably a few more examples out there, but I write too much python to effectively identify them
On one hand, custom operators are cool. On another - Perl.
yeah, definitely not a feature I want in python, they do solve some things though
You could also think of explicitly handling absence or failure, like Rust's Option, with Some and None. It's doable with if arg is None, but it's less powerful. I guess structural pattern matching allows you to use similar structures in a less formalised way.
there are structural reasons that Python would have a hard time with fully custom operatorss
what do you mean?
Incremental parsing is what is usually chosen for those type of languages
not just precedence, but the lexical question of what is an operator?
Oh boy
Languages with custom operators usually restrict the set of usable characters, so tokenizing the source is never ambiguous.
Maybe you could store it in the AST without knowing precedence, and then look up the precedence at runtime. But this will be quite slow, I suppose.
Scalaβs custom operators are p dope
@grave jolt raku will let you make operators out of anything, even if it may cause ambiguity. But it doesn't allow adding them in the repl sadly.
but as I said, I don't think this a good thing for python even if it were technically possible, since these things tend to be very error prone and difficult to use
@wheat beacon hello, this isn't a help channel, please read #βο½how-to-get-help to see how to get help
ye was just seeking for more "advanced" help so my help request doesn't go to waste
although PIL is not that "advanced" imo
π
this is not even advanced help channel, it's about discussing the language itself π
Exactly. "Advanced" is not well-defined for a language feature or a question.
The name might not be the best, but we tried many different versions, and it's our compromise
You might have a difficult problem, which is, well, difficult despite one's language level.
bruh smh
Hey all how can I run two API's using request I want to run both at the same time
That would be a better question for #async-and-concurrency
Cheer's bud!
This is not a help channel. Try #data-science-and-ml
Python has matrices as a first class type?
interesting; I wasn't expecting to create a matrix semantic concept this early on; maybe for some mathematical language
hmm, it isn't a matrix; just a list of lists?
yea
python does have a @ operator that is used by some libs for matrix multiplication
but the gramma say @ operator is for matrices
what happens if you use @ without such a library?
i mean any class can define def __matmul__(self, other): ...
k
or __rmatmul__ or __imatmul__
how pervasive is floor division across languages? is // mainly a python thing?
not really a python only thing
hmm, it seems to be a useful enough concept for me to make it a first class semantic concept
ik that C has the function floor()
it mostly depends on each language because alot use // as a comment and opt to use a method to perform floor division
the actual syntax is less interesting as to the question of it being a common atomic operation
statically typed languages use / for both flooring and integer division, it seems
depends on the lang
some things will apply the numerical bounds rather than necessarily flooring it explicitly
OCaml uses /. for division of floating numbers and / for integer division (because it doesn't have ad-hoc polymorphism)
but you can define custom operators in OCaml, so it's a whole other story
I just like the semantics in python that floor dividing a float will still return a float 
lol
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
True
not looked at that yet
btw how are you planning to support the C api ?
or are you just not gonna do that 
what do you mean by C api?
i mean python's c api
make an alternative FFI that will only allow writing extensions in JavaScript

you mean how you specify an external C function in python?
yes
I mean, technically that's going to provide an FFI for C++ as well, since Node allows that AFAIK
are you going to support the semantics the same e.g. allocations and reference counting
it does indeed
but from what ive seen of it, its hell compared to python's 
I will be supporting everything that isn't specific to a particular Python implementation
and I mean... JS is faster than Python
Python's C API isn't "external C functions".
right, no, it's not the external functions
it's how CPython is structured so that C extensions can manipulate Python stuff, right?
so what is "Python C API" then?
I mean that is because of the JIT compiling + the locked down nature of the language meant alot more things could be easily optimized without worrying about language semantics
it's the ~700 C functions that underpin the CPython implementation.
that and JS learnt alot from Python already 
no I will not be supporting anything that is specific to CPython
Grown up languages aren't tied to a particular implementation
or even worse a particular version of a particular implementation
You're saying that about a 30 year old language which became immensely popular with fields due to the C api
does PyPy support these 700 CPython functions?
a winning marketing strategy for your product π
it provides hooks for them yes
not that it needs them because it's still built of Cpython
but yeah what ned says
what does that mean?
you're product is dead to the python community from day one without the C api
you know idk, that sentence doesnt make much sense
ok π
where is this C API documented?
you aren't going to like it....
no I will not be supporting that.
however someone could create a compatability layer if they felt the need
it's fine to build an implementation that doesn't support it. It's a bad move to insult people while you do it π
I dont think anyone would be dedicated enough to the whole system when they could just use the normal interpreter and reap the benefits
ISO Standard language are not defined in terms of a specific implementation: this is what I mean by "grown up". Why do you insist on conflating valid criticism of a language with individuals nedbat?
ok. it's a bad move to insult the language while you do it. People will take it badly.
people will conflate that criticism.
you mean some people might take it badly
marketing is about dealing with people. I can't change that.
The difference is that any implementations that are serious support the C api because it makes up such a large amount of the eco system
I don't constantly step on eggshells
right. Marketing.
Not choosing to support the C api basically means you're cutting out support for the entire Data science eco system that is so popular with python along with the async eco system etc...
There's just no point in talking about "grown up" languages. Implement what you want. why the insults?
database drivers etc....
so this C API is this the PyPy compatibilty layer people keep mentioning?
PyPy generally isnt used with C modules because it doesn't give any benefit but it does provide support to be able to compile extensions against it
PyPy implements the Python language version 2.7.18. It supports all of the core
language, passing Python test suite (with minor modifications that were
already accepted in the main python in newer ver
then if I find the time I might do something similar but it isn't a priority. I am not reinventing the CPython implementation; I am implementing the language
because Python is popular
okay, but from what you've said you're going to remove some of the biggest things that make it popular (at least in the industry)
as I said I might create that compatibilty layer but it isn't a priority given my primary use-case.
what is your primary use case for this 'version' of python then
one of several scripting languages that my toolkit will support
okay ...
sure...
@radiant fulcrum https://neos.dev
neos Universal Compiler and Bytecode JIT
ive already seen that
basically I would need to provide "binding plugins" to support such things but what you say about PyPy it doesn't seem to be that necessary
well i guess we can just hope that your skill in implementing a language is better than your web ui skill 
I guess this is one of those times where nedbat says I am insulting people when I am not but nedbat also ignore a genuine insult directed at me.
implementing JS for that thing would be way easier than implementing Python lol
I don't like insults, so people shouldn't do it. My point was that you are building a product, but are pushing people away while talking about it. That's bad marketing.
the reason why I am doing Python is simply down to its popularity
Yay for python!
isn't JS much more popular? basically every website uses JS
nah
I understand that. Why talk about "grown up" languages? It's pointless aggression.
they're actually incredibly close
Js did win out on SO dev survey
and equally JS has two main language specs
well, it's not clear how to compare 'popularity' of languages...
nedbat why keep bringing it up? the conversation has moved on.
because it's not the first time you've done it, and you haven't answered me here about it.
if there are many SO questions, doesn't it mean that the language is confusing, not necessarily poluar? π
Im guessing NodeJS itself is probably less popular than Python
because he was obviously afk and could reply only now...? when you were complaining "oh, nedbat doesn't see a problem with x", so he replied?
ECMA 5 is likely to be as popular if not more due to browsers running it
Question count may or may not be a good indicator. But the dev survey is decent. I think.
no nedbat is going back to my earlier, valid criticism of Python not being standardized by a recognized standardization body
I mean "grown up" doesnt make any sense though 
he literally replied to "I guess this is one of those times where nedbat says...". you literally posted it one minute before nedbat replied to it???
I will conceded that this is my personal opinion but I consider a language to only have matured once it is standardized, hence my words "grown up".
So you wouldnt call JS, Java etc... "grown up" 
any langauge that is defined in terms of a particular version of a particular implementation is inferior to being properly standardized so anyone can create an implementation without reference to another implementation.
Let's not turn this into a this and that thing. For what it's worth leigh, there's good advice in what Ned said. Bad marketing will come back to bite you, and using the words "grown up" is definitely not conveying what you hoped it would convey. Anyways, up to you whether you want to take the advice or not there, but I'm hoping you can put aside the emotions and just see it from the perspective of those who'd be trying to use the tool you're building.
So no one disputes your stance, just the choice of words won't come off as you hope it would.
Python isn't defined in terms of its implementation, it's pretty clearly stated what's standard and what isn't
this 700 function C API that uses CPython structures seems awfully implementaiton specific to me
I'm not sure how to break it any other way, Cpython definitely gets an edge because of how readily it can interface with C code.
it is implementation specific, however its one of the biggest implementation details that are chosen to be support by other implementations because of the support and advantages it brings to Python
it doesnt have to
But that's tricky.. Because that's more of a real world "blurring" on lines between languages
Simply because these are a means to an end.
but it removes a incredibly large amount of the eco system that exists and has been built around Cpython and the C api
anyway I don't wish to ruffle any feathers so I am quite happy for the subject to change.
Well, yes, and it's clearly not part of the standard (i.e. what is Python). Any pure-Python code will work without them
and that is what I am doing in the first instance
One of the main points of python is its large package ecosystem; a big amount of those packages will use extension modules in their backend for efficiency which (maybe unfortunately) means that implementations that wish to use them have to support it in some way
making an implementation that supports pure Python code
That's a reply to
any langauge that is defined in terms of a particular version of a particular implementation is inferior to being properly standardized so anyone can create an implementation without reference to another implementation.
Not sure in what way Python is defined in terms of its implementation.
Fair. The only heads up there is that pypy went there, and isn't seeing major adoption perhaps because of it.
okay sure, but the point everyone was trying to make was the reason that python is so popular is it's eco system which has adapted to python's lack of speed and resulted in the massive C api support
there isnt really much point to use PyPy or anything else for 'speed' when using C modules
like i wouldnt run PyPy on numpy or what ever
I think what Leigh is trying to say is that they're not trying to make a usable Python implementaiton, but to implement some language in their compiler as a proof of concept, or demonstration that it works.
not an example
i'd use Cpython, maybe if i wanted an extra boost in speed (god forbid) i'd just stick numba onto it
that pretty much gets it as close to native speed as possible anyway
Asked this question on #async-and-concurrency. Don't know if this is a better place to ask.
not really the best place to ask 
async was the right channel
@grave jolt I am adding Python as a scripting language that can be used with my toolkit; so you will be able to create modern looking GUI apps and 2D/3D games and use Python to do that as an option
but you cant do that with Pure python because it needs to interface with the raw C api or some other systems level interface
so you'll either need to support already existing gui stuff (which might need C extensions, so C API as well)... or just make your own gui python library...
you will be able to call C functions from my Python implementation
okay but who's going to implement the C functions to produce those 2D/3D games
@limpid forum the GUI is something I have created.
me
my universal compiler will have bindings that will interface to my toolkit so will be reachable from Python
π€¨
so you basically have an api
but you have to make the bindings
so why implement whole languages for one api bindings?
I am not
the input language being Python is lost in the translation before conversion to bytecode; so the same C API will be used by Python and JS for example
the bindings would still need to be basically a full lib, so it can be used nicely
well it just means creating a C API around my C++ API
which I will only have to do once and it will work for all supported languages
how would you define colours? shapes? you'll either have to work with pure(r) values or make the classes etc to make the usage nicer
TBD
I already have support for properties in my API
and that includes simulated reflection for enums and such
what my toolkit's GUI looks like:
@limpid forum what I can do is defne such classes in Python that call into my C API under the hood
there are various approaches I can take
and/or C++ API
back on topic. the + operator (positive) is that a no op or is it something that can be redefined?
but I assume for normal default behaviour it behaves as expected; i.e. +-2 == -2
how do you invoke the evaluator in this channel?
yeah, it's a no-op on integers/floats
only helpers+ can do that IIRC
k
besides help channels, #bot-commands and #esoteric-python
!e
but, of course, it doesn't have to be a noop
class _Plus:
def __init__(self, i): self.i = i
def __pos__(self):
self.i.value += 1
return self.i
class Int:
def __init__(self, value): self.value = value
def __pos__(self): return _Plus(self)
def __repr__(self): return f"Int({self.value})"
n = Int(40)
print(n)
print(++n)
print(++n)
@grave jolt :white_check_mark: Your eval job has completed with return code 0.
001 | Int(40)
002 | Int(41)
003 | Int(42)
I am looking forward to how I am going to solve that problem
working out π
everything I am doing is an order of magnitude harder as I have to solve it in a language agnostic way: if I was just writing a Python compiler directly in C++ it would be trivial π
so even though it is harder hopefully the pay off will be bigger if 90% of what I create is reusable with different languages.
and that includes things such as debugging and syntax highlighting for the editor
\o/
sorry to brign in back but what languages are standratized then? Most that are used nowadays are still in development and can change over time...
maybe i don't undertand what's "standartized"
Haskell has an "official standard" (The Haskell Report), but most useful libraries use GHC-specific extensions anyway, so
This category lists programming languages with an ISO standard, current or obsolete.
What's the difference between an ISO standard and a non-ISO standard (like Haskell Report)?
ISO is an internation standards organization that isn't just about programming languages
ok but standard evolves over time too?
"ISO STANDARDS ARE INTERNATIONALLY AGREED BY EXPERTS
Think of them as a formula that describes the best way of doing something. " https://www.iso.org/standards.html
we should not start debating the value of standards....
Not sure how an ISO standard makes the implementations any more compatible. SQL is an example of a language where implementations add quite a lot of extensions, so that it's not much practical to write "ISO SQL"
@spark magnet why not?
because it's contentious and off-topic
that is certainly an opinion.
i guess you either think it won't be contentious, or it is on-topic?
I would say it is on topic for this channel; it is advanced meta.
possible future standardization of Python is certainly within the scope of "future of the Python programming language" - this channel's topic.
nah. I just wanted to understand. had no intention to restart on it.
sorry, who?
Leigh not you haha, have a nice rest of your day!
if anyone is being pushy here it is nedbat. he cannot seem to tolerate anything he perceives as slightly negative regarding Python
Hmmm well I don't think that is very true but I am gonna withdrawal myself from this conversation before anything bigger happens
I'm fine with critiques of Python, i have some of my own.
withdrawal
you are pushy.
and you bring dramas from other forums into new forums; you seem to have an issue with me as an individual. you are not being professional.
anyone selling popcorn rn
i'm not sure what i said today that seemed like an issue with you. I said it was bad marketing to make empty insults about the language you've chosen to implement.
you know what you are doing; you have done it on IRC, Usenet and now here. Stop obsessing over me as an individual.
this is rapidly going off topic
I suggest we return to the applicability of monadic composition to Python
i'm interested in your project and its progress. You keep talking about it here. Do you want attention on the project, or you don't?
this is a technical forum so keep it technical not personal.
this is literally personal; if you have a problem with it, I suggest @summer lichen
nedbat has dismissed my project on multiple occassions as he thinks it is not possible to achive its goals and he therefor assumes my project has no value and I am here to troll. but this is off topic.
can you show me where in this forum I have said that?
you have done it in IRC and Usenet and the pattern is being repeated here
two wrongs donβt make a right, and Iβm not a mod. just a suggestion.
or, show @summer lichen where I have.
Is an ASGI application a monad? There's clearly flatten
def flatten_asgi(nested_app: Callable[[Scope, Receive, Send], Awaitable[ASGIApp]]) -> ASGIApp:
@wraps(nested_app)
async def _app(scope: Scope, receive: Receive, send: Send):
generated_app = await nested_app(scope, receive, send)
return await generated_app(scope, receive, send)
return _app
, but can it be viewed as a parametrized type over an arbitrary type?
yes, change topic is good; don't want ****show here
I actually thought about this before
let me try to remember
okay so the thing is
I donβt think so because
of the monad laws?
specifically associativity
because ASGI applications are not pure functions
Haskell's IO isn't pure either
Before we even get to the laws, a monad is a type constructor, not a concrete type
so maybe there's some other notion of a composable thing?
βa functor is not a containerβ
wdym?
I meant that a monad has kind type -> type
yeah, it was a related article
In Python terms, it's a generic type parametrized by a single type
distinguishing between the monad/functor as a higher-kinded type
and the actual concrete types (which are often colloquially referred to as the monads/functors themselves)
Maybe ASGI apps form a category?
that seems quite ridiculous lol
I should ask that on some mailing list on 01.04
Start simpler and try to come with a way in which an Asgi app is a functor
Yeah, that's a good question. I guess it doesn't make any sense because you can't make ASGI a parametrized type in an arbitrary type.
But maybe you can make it parametrized by some restricted set of types?
You've said that you plan to implement Python because it's popular, but most of the things that make it popular are libraries that only work on CPython or pypy. It's not too tough to make a Python implementation - there's a fair number of others, beyond the big two. But they're rarely used outside of specific niche cases, because they can't do the things that Python is popular for.
Jython was moderately popular for a while, though it never successfully made the leap to Python 2. The value proposition of Jython was that, while you lose the ability to use CPython extension modules, you gain the ability to use libraries that run on the JVM. For some developers, that was a good trade-off.
In the case of your implementation, it's not clear what your value proposition is. By switching to your implementation, people would lose the ability to use many of the most popular and powerful libraries. What do they get in exchange that would make it worth their while to use your implementation?
It seems like your intention isn't to create a toy implementation, and you'd like to have actual users. If that's the case, you'd do well to consider those actual users' needs, to be sure that what you're building meets them.
Outside of CPython and pypy, the other implementation that's reasonably popular right now is MicroPython (and its fork CircuitPython). The value proposition for those is that it's a stripped down implementation that can run on severely resource constrained environments like microcontrollers, and that it doesn't require an OS to host it.
(MicroPython technically isn't Python Python, right?)
It's a mostly compliant Python 3.4 implementation.
It has some differences, but not many. Other than that it doesn't ship with big chunks of the stdlib.
That said, I don't think that keeping up with the language as it evolves is necessarily one of the project's goals. It's certainly less of a priority for them than supporting a wider range of hardware.
well, 1or 2 not working pretty much makes it useless /s
Technically Cython is an implementation as well. Its value proposition is that it transpiles your Python code to C or C++ code that can be loaded into CPython (or possibly pypy) as an extension module.
The value proposition being potential speed improvements and ease of integrating with existing C and C++ libraries.
my value proposition is being able to use Python with my toolkit
the easier (and arguably more mechanically useful) method would be to write a cpython extension module in c/c++ to allow your program to interface with python easily
of course that is just my opinion
but it is likely that if/when you are successful in making neos you will end up with a language that is like, but not quite the same, as python
no, Python will be one of several languages I will support via my language agnostic scripting engine.
my second point still stands
any language implemented in neos will behave slightly off from the source language. That will confuse users (imo)
that is not the plan; I intend to fully implement the language
do you plan to implement undefined things?
like globals()['a'] = 1 setting the global variable a to 1?
I do not plan on implementing any quirks of specific implementations
actually that is a defined thing in python
as is eval, exec
when you get to C will you implement integer overflow?
I will implement the semantics of C as defined by the C ISO Standard
Ok, fair
@weary garden you still have not answered my question here
i corrected myself, that behavior is defined (afaik)
I am not yet familiar with that area of Python; I only started learning the language on Friday
So your value proposition is that people who are already planning to use you toolkit will be able to use Python with it. The people who choose to use your Python implementation will be a subset of the people who choose to use your toolkit. Right?
correct
Does your toolkit have users yet?
nope
So your toolkit is your primary concern, but you're choosing to prioritize a Python implementation over it?
the scripting engine is an integral part of the toolkit and Python will be the first scripting language I will support
Perhaps it would be better to start with a Lua implementation. It's a smaller language, without a real stdlib, that is designed for embedding into new environments.
Lua is on the roadmap
I am choosing Python first due to its popularity
after implementing Python I will have likely implemented most semantic concepts that Lua requires making the Lua implementation trivial
Right, but its popularity isn't relevant. You're not trying to attract users of any other implementation, so I don't see how its popularity benefits you.
because people who know Python already will be able to do neoGFX scripting without too much hassle
Sure, but at the point where they have to learn your entire toolkit, learning a bit of Lua is hardly any extra ask.
Someone who knows Python can pick up Lua in an afternoon.
And master it in a week.
the actual language I choose doesn't really matter; I have decided on Python for no other reason that its popularity and it is an excuse for me to see what all the fuss is about
I am also doing it to prove a point
So if it fair to say that you don't care whether any existing 3rd party libraries work with your implementation, because your only concern is using the language to interact with your toolkit?
I may add support for C Python extensions at a later date but it isn't a priority
I like to cross bridges as I come to them
Well, there are no popular implementations that don't support the C API. This is not a coincidence, you're choosing not to implement a crucial feature that contributes to the popularity of the language. Python + C API is a popular language. Python without C API is not. It's pretty much only used on microcontrollers.
I am interested in getting numpy to work tho as neoGFX will be good for data visualisation
Numpy will not work without the C API.
So, correct me if I'm wrong, but it almost sounds like you're trying to make this project harder for yourself, and more of a challenge.
Lots of numpy is written in Fortran.
creating a universal compiler that can compile any programming language is a fun challenge yes: and you will get syntax highlighting, visual (text and node) debugging with any programming language for free with little to no effort on my part.
With no effort on your part? How will you do that? Combining things that already exist?
Leigh means that once the universal toolkit does syntax highlighting (for example), then any new language added to it will have syntax highlighting without extra effort.
Oh, got it.
because once the semantic concepts are in place the source code is mapped to those concepts for debugging purposes (or syntax highlighting purposes) in a language agnostic way: I only have to do it once so then adding a new language is not much more work
I have lots of things with equal priority to do
If everything is high priority, nothing is.
indeed but such is life
Regardless, if it's just an intellectual exercise, there's nothing wrong with that. Building compilers is fun. If you want it to actually be used by people in lieu of CPython, you should pay attention when current CPython users tell you what features are must-have for them.
no I fully intend to monetize it; my initial market will be the space currently occupied by Qt
Why would someone choose neogfx over PyQt5?
I am not familiar with PyQt5 but neoGFX will be cleaner, less bloated, less legacy cruft, faster and higher quality than Qt
Prioritizing multiple languages right at the outset seems like a poor way to take a bite out of Qt's market share. You'd probably do better to pick a language which they serve poorly, and make neogfx the UI library for that language. And then work from there to expand to other languages.
That gives you an immediate captive audience: people using that language, who currently have no high quality graphics toolkit option.
as I said the language choice will have no bearing on what I am doing now
the language doesn't matter
so Python is as good a choice as any other
once that is done adding new langauges is a lot less effort if 90% of the semantic concepts libraries I created can be reused
what semantic concepts would Haskell be able to reuse? I don't think there's a good mature GUI toolkit for Haskell
again Haskell is another language I need to learn but there will be type-based semantic concepts I will need to create even for a non-FP language
Clearly it has some impact. You're learning the language and trying to represent its grammar.
I am getting four things out of this exercice: 1) fun 2) challenge 3) learning new languages 4) possible pocket money
And you're discovering semantic concepts that are specific to Python, which you could be skipping over for now if they're not relevant to other languages.
I don't believe I have discovered any concepts specific to Python so far
but I have only been looking at this since Friday
even significant whitespace isn't specific to Python
The MRO perhaps. The behavior of super() without arguments, maybe. Reflected operators, perhaps.
len(x) --> x.__len__() is particular to Python
the form maybe but not the underlying concept
Reflected operators are, afaik, specific to Python, though. I'm not familiar with another language with something similar, at least.
python's function closures storing values is not something ive seen in most languages
I could reduce this down to the fact that a Universal Turing Machine can compute any computable problem. I am of the view that what I am attempting is not intractible; the only hiccup would be me getting run over by a bus.
ie: py def foo(n): def bar(): return n return bar
that seems like a standard closure, no?
i just remember trying to do it in C and not being very successful
a-b calls type(a).__sub__(a, b) and, if that returns NotImplemented, calls type(b).__rsub__(b, a). That's atypical. And only makes sense in dynamic languages without the ability to overload functions based on argument types.
you can capture values by reference or value in C++ lambdas: I see little difference there
@raven ridge how about descriptors?
Ooh, that's a very good one.
or another fun one, the fact that dunders can change at any time
well I need to support self modifying code too
super() in Python delegates not to the parent class, but to the next class in the method resolution order, which is not known at compile time. That's very different from most languages.
what's the idea behind radd/rmul? When would those be used?
Descriptors allow an object that is an attribute of another object to decide what happens when they're accessed. They can do some deep, dark magic. As can metaclasses.
that's so you can do 1+myobj
why would you ever want them to not do the same thing?
you do want them to do the same thing.
libffi actually has a neat way to creature closures. http://www.chiark.greenend.org.uk/doc/libffi-dev/html/Closure-Example.html
well, if add is commutative.
string adding isn't commutative.
isn't it the same operation tho?
It's not to allow them to do different things. It's to allow adding an instance of B to an instance of A, even though the author of A didn't know that the type B would ever exist.
def __radd__(self, other): return other+self
the operands have to be switched
if you create your own integer-like class, and try to do 1 + YourInt(), it would just fail if __radd__ didn't exist - it would try int.__add__, int would say that it has no idea what a YourInt is or how to add 1 to it, and it would give up.
__radd__ gives both classes a chance to define what the + operation means with that pair of argument types.
the left class gets to try first, with __add__, and if it doesn't know what to do, the right class gets to try second, with __radd__
oh ok I see what you're saying
that's actually a really neat feature
do any other languages implement something like that or is it pretty exclusive?
I've never seen another language that does it, but Python is the dynamic language I know best. In statically typed languages that would just be resolved by adding function overloads and determining what function to dispatch to at compile time.
The C++ equivalent would be defining both
YourInt operator+(int, YourInt);
YourInt operator+(YourInt, int);
right right
I'm not familiar with another language that allows operator overloading and that needs to determine which class gets to choose how the operator overload is dispatched at runtime. Ruby probably has this same problem, but I don't know how it handles it.
actually I had no idea operator overloading was a thing in c++
C++ is great π
it looks like that was one of the things left out from c[++] in java
I don't think Ruby can do this, actually, after a few minutes of googling. It looks, at first glance, like a + b only ever calls the equivalent of the + method of the class of a, and b never gets a chance to decide what to do

