#internals-and-peps

1 messages Β· Page 97 of 1

weary garden
#

lots todo! πŸ™‚

visual shadow
#

re dunders, i forgot where i read it, but the message was: python devs used dunders so that you dont have to

undone hare
#

I believe originally dunders were intended to be used by library creators, not end users

grave jolt
undone hare
#

Probably not init, not sure about the other two to be honest

grave jolt
#

Also comparison operators for priority queues and such

grave jolt
undone hare
#

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

grave jolt
#

well, dunders aren't about reflection

#

they're for operator overloading and similar stuff

undone hare
#

But they allow the same kind of meta programming

#

I guess they are used for simpler stuff yeah

grave jolt
#

what do you mean by dunders then?

#

actually, it's all mixed in Python a bit.

undone hare
#

Yeaaah

grave jolt
#

The reflection API is somewhat scattered across dunders, inspect and some other modules.

#

So dunder methods are for overloading.

undone hare
#

That was a poor example

grave jolt
#

And dunder attributes are mostly for reflection

weary garden
#

is reflection implementation specific or standard?

#

"standard" in inverted commas of course πŸ™‚

grave jolt
#

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.

raven ridge
#

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.

grave jolt
#

well, if your implementation is stackless, that might not work πŸ™‚

raven ridge
#

indeed, indeed.

#

the most commonly introspected things are function/class names, docstrings, and annotations, I would think

spark magnet
#

seems like people use the terms introspection and reflection interchangably

weary garden
#

is that an accurate statement? "nobody is using anything besides CPython and PyPy"?

peak spoke
#

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

severe lichen
#

Jython and IronPython are horribly outdated.

weary garden
#

of course my implementation will be the newest when it is released! πŸ˜„

peak spoke
#

ironpython3 is being worked on I think but I've no idea on the progress being done there

spark magnet
weary garden
#

if Python had an ISO Standard CPython would become less important.

severe lichen
#

@peak spoke And then Python 4 comes out right before release πŸ™‚

#

BTW, what's that new stuff from MyPy, which is basically compiled python?

peak spoke
severe lichen
#

And I've heard a lot about Nuitka and Cython, but I don't really know how popular they are in practice.

peak spoke
#

I think cython is used fairly often

radiant fulcrum
#

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

sacred yew
peak spoke
#

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

radiant fulcrum
#

yeah

#

but thats because they use two diffrent systems in order to compile

spiral locust
#

Hi

#

i search help please

cedar ice
#

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

grave jolt
#

Isn't nuitka based on CPython? Or does it have its own runtime from scratch?

peak spoke
#

It uses cpython

#

I wouldn't really call either implementations

true ridge
#

I would say beside those implementations the major ones are MicroPython and RustPython.

raven ridge
#

CircuitPython is a fork of MicroPython that's pretty heavily used as well, in a certain space.

true ridge
#

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)

spark magnet
true ridge
#

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

cedar ice
#

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

true ridge
#

though we are talking about 'implementations'

spark magnet
#

my rough guess: >99% CPython, of the rest, >99% PyPy

radiant fulcrum
#

seems about right

cedar ice
#

Accurate

radiant fulcrum
#

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

uncut sage
#

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.

grave jolt
#

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.

uncut sage
#

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.

weary garden
#

any type theory expers here?

spark magnet
weary garden
#

not directly.

spark magnet
#

better to just ask

weary garden
#

would you consider a 1-tuple and an ordinary value type to be equivalent?

spark magnet
#

for example, (1,) == 1?

weary garden
#

I am not talking about Python's interpretation but more generally

spark magnet
#

this might be the kind of question where languages differ.

weary garden
#

no, my question is concerning type theory

grave jolt
#

Well, they are isomorphic, of course. I don't know any other language that has a 1-tuple.

raven ridge
#

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.

weary garden
#

I am not asking how different languages' tuple abstractions; I am asking in the context of type theory

raven ridge
#

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.

weary garden
#

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

raven ridge
#

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.

weary garden
#

again you are thinking in terms of programming language abstractions

#

I am asking about type theory-level abstractions

spark magnet
#

i'm not sure what the point is of type theory if it doesn't describe how programming languages work.

weary garden
#

let me put it another way: how would an "int" and a 1-tuple of an "int" behave differently

raven ridge
#

a 1-tuple-of-int has a length, an int doesn't.

weary garden
#

true

#

that answers my question

raven ridge
#

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.

spark magnet
#

there aren't many operations they share.

#

maybe only the ones they both get from object.

weary garden
#

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

spark magnet
#

so language.type.tuple can be a tuple of assignment targets?

weary garden
#

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

spark magnet
#

hmm but in a,b,c = 1,2,3, there are sort of two kinds of tuples at work.

pliant tusk
#

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.

weary garden
#

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?

pliant tusk
#

yea like most applications that allow scripting like this do

weary garden
#

I prefer the scripting engine approach rather than bindings.

#

someone can always create bindings if they have the time

pliant tusk
#

but why would you reinvent the wheel?

weary garden
#

besides I will be creating neoGFX bindings that neos will be calling into

#

surely you know there is only one answer to that question?

pliant tusk
#

and what is that

weary garden
#

NIH of course

pliant tusk
#

what is NIH?

weary garden
#

Not. Invented. Here.

spark magnet
spark magnet
#

"we don't trust anyone else to do it well"

pliant tusk
#

that seems like a flawed sentiment

weary garden
#

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.

spark magnet
#

it's usually used to point out a flawed sentiment, yes.

raven ridge
#

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.

pliant tusk
#

@weary garden then why not build a new CPU for neos? or better yet redefine computing to not use CPUs?

weary garden
#

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

pliant tusk
#

you believe that you can personally reimplement python (and several other languages) better than people who have been working on the platform for years?

raven ridge
#

you may want to stop using "NIH" for that. You're definitely misusing it; the term has a definite negative connotation.

grave jolt
#

Time to create a new abbreviation πŸ˜„

weary garden
#

@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)

pliant tusk
#

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.

weary garden
#

disagree.

spark magnet
#

@weary garden you are implementing python, and you do believe you will do a better job than existing implementations. right?

grave jolt
#

let's just wait for the Python implementation and see. I don't think these discussions here are very productive

weary garden
#

I am implementing a universal compiler and Python will be the first language schema I will create

spark magnet
#

and you think it will outperform existing implementations. Right?

weary garden
#

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.

spark magnet
#

wise πŸ™‚

pliant tusk
#

to clarify, you expect neos to out perform all the language schemas you plan to implement

weary garden
#

no, I expect neos Python implementation to be faster then PyPy and by implication CPython.

spark magnet
pliant tusk
#

fair enough. @weary garden let me know when you have a working alpha, id love to test it out

weary garden
#

thanks πŸ™‚

raven ridge
#

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.

grave jolt
#

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?

limpid marten
#

Can you write extensions for PyPy that don't have to rely on some overhead that simulates reference counting?

raven ridge
#

pypy doesn't have its own C API, AFAIK

spark magnet
#

... since there's no C πŸ™‚

grave jolt
#

ah rightht

raven ridge
#

well, it's own c-compatible ABI, anyway. That doesn't require C, but it still doesn't have one.

fast nest
frozen thistle
#

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

fast nest
#

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

unkempt rock
#

Is there a known way to get answers in google forms?

grave jolt
pliant tusk
#

if you mean to get response data, yes you can with the google api*

#

*only for forms you own

weary garden
grave jolt
#

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?

misty iron
#

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 ?

gleaming rover
#

I just did some reading about this stuff

#

don't have an answer, but I learnt something new

visual shadow
severe lichen
#

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

visual shadow
#

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

severe lichen
#

Well, both lambdas and ternaries can be replaced by functions, but they are still useful.

visual shadow
#

yeah i cannot give any further insights besides what's already stated in that rejection notice

gleaming rover
#

what do you think of Python style ternaries vs C style ternaries

#

specifically, the order of the operands

peak spoke
#

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

swift imp
#

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

feral cedar
#

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

spark magnet
#

C's use of colon in the ternary makes no sense.

#

a colon connects a thing to the thing it introduces.

swift imp
#

Oh yeah, I've never found C's ternary to be intuitive at all

visual shadow
#

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

gleaming rover
#

syntax aside

#

like just the operand order

#

Python is the only language I know that has it this way

spark magnet
#

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"

feral cedar
#

c-style matches the flow of a normal if statement though

boreal umbra
#

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?

gleaming rover
unkempt rock
#

anyone know what happend here?

feral cedar
#

change all your tabs to spaces

unkempt rock
#

thanks

flat gazelle
#

I think I find if condition then expr else expr easiest to parse.

weary garden
#

disagree: there are lots of contexts where a colon is used as a delineator

#

e.g. IPv6 addresses

spark magnet
#

to be fair, Python uses the colon for slices. I don't know of another place that uses colons for alternatives.

grave jolt
#

I actually like ?: in JS/TS

#
return foofoofoofoo
       ? barbarbarbar
       : bazbazbazbaz
         ? fizzfizzfizzfizz
         : buzzbuzzbuzzbuzz

even something like this

#

but that's maybe too much

flat gazelle
#

For that I generally prefer the haskell language extension which allows

if | cond = v
   | cond'=v's
grave jolt
#

Is there a syntax form for which there isn't a haskell language extension?

grave jolt
#

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

grave jolt
boreal umbra
#

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?"

sacred yew
#

trigraphs use ? :P

grave jolt
#

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

boreal umbra
spark magnet
grave jolt
#

well, how does the colloquial meaning of class match OO classes?

boreal umbra
grave jolt
#

well, yes

grave jolt
#
@dataducky
ducky Point:
    x: int
    y: int
boreal umbra
#

aren't we just talking about how language is fundamentally arbitrary now?

grave jolt
#

yeah πŸ™‚

#

I guess some words are just somewhat useful mnemonics

boreal umbra
#

Language is fundamentally arbitrary πŸ’₯ πŸ₯³

spark magnet
#

"class" definitely means something that "ducky" does not.

grave jolt
#

You define a ducky, and you can call it to create ducklings.

spark magnet
#

good luck with your new programming language πŸ™‚

grave jolt
#

Well, maybe it means something in the context of mathematics.

boreal umbra
flat gazelle
#

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.

spark magnet
flat gazelle
#

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

grave jolt
#

blueprint might actually explain a bit more

flat gazelle
#

since the thing tends to be more complex than a single word holds

boreal umbra
spark magnet
#

"First-class mail"?

flat gazelle
#

class does mean category even for non programmers

spark magnet
#

one of the well-known meanings of "class" is a category of things

boreal umbra
#

fair enough

grave jolt
#

does that mean that the name would be short for category, cat?

flat gazelle
#

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

grave jolt
#

agree

#

but, as you said, too much operators can get out of hand very quickly

flat gazelle
#

I am not arguing for replacing class with |_| anytime soon, but I will also not argue for replacing : with do nor + with plus

grave jolt
#

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#

flat gazelle
#

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

sacred yew
#

doesn't template have some other purpose other than declaring templates

flat gazelle
#

not actually what I meant, but that one is on me for picking something ambiguous

grave jolt
#

ah

#

well, yes, it's often hard to even google for such things

raven ridge
grave jolt
#

I think google has improved on its non-letter search lately tho

flat gazelle
#

ye, and things like hoogle and the raku search are becoming more standard

grave jolt
flat gazelle
#

ye, it is a tradeoff

grave jolt
#

maybe it would be useful to create a simple page that maps non-letter operators to their names

#

(for Python)

raven ridge
flat gazelle
#

I find python is about right in the operators.

grave jolt
#

yeah

flat gazelle
#

I would prefer custom operators over overloading most of the time though

#

but custom is much easier to create abominations with

grave jolt
# grave jolt yeah

but granted, it's not used anymore, apart from... half of the tutorials lemon_pensive

flat gazelle
#

and the logging module

raven ridge
#

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.

grave jolt
raven ridge
grave jolt
grave jolt
flat gazelle
#

when putting values into json in string literals, format is no nicer

grave jolt
#

I don't think I understand what you mean

flat gazelle
#
"""
{ 
  "key": 34,
  "more": {
    "nested": {
      "keys": [%d]
    }
  }
}
"""
``` trying to do this with .format would be annoying
grave jolt
#

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?

flat gazelle
#

we don't have lens

#

can't really create a setter into a nested structure in a nonpainful way

grave jolt
#

well, you can mutate it πŸ‘€

flat gazelle
#

then you have to deepcopy everytime and its a whole mess

#

this is easier for small scripts

grave jolt
#

maybe yes

flat gazelle
#

for large projects, you would probably want to use something safer

grave jolt
#

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

flat gazelle
#

I would probably just write a bfs that would just look for ... in the literal and replace them in order

limpid forum
grave jolt
#

oh right, thanks

#

that's a useful link

#

although it still doesn't mention things like decorators, but

raven ridge
#

in fact, .format is pretty much the only string formatting option that I never use.

limpid forum
limpid forum
# raven ridge `.format` is slower, and I dislike its placeholders compared to the old ones tha...

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.

raven ridge
#

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)

fallen slateBOT
#

@raven ridge :white_check_mark: Your eval job has completed with return code 0.

Hi, Nicky!
small epoch
#

hello

ember egret
#

hello

limpid forum
# raven ridge !e ```py s = "%(greeting)s, %(name)s!" args = {"greeting": "Hi", "name": "Nicky"...

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

raven ridge
#

Those all sound like things that are just a matter of preference - which is fine, we can have different preferences.

coral drift
#

wassup famm

#

what to learn after decorators and generators

spark magnet
coral drift
#

not only that i made corators with *args and **args that also use yield!

#

a python super function!

spark magnet
#

what's the largest project you;ve made?

coral drift
#

wanna see my porngithub? can we share here?

#

the largest project isn't in python, but in verilog

spark magnet
#

i'm wondering about python projects.

coral drift
#

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

spark magnet
#

you can get the source and read it

coral drift
#

i don;t get that shit

#

tl'dr

#

i have room temp iq

swift imp
spark magnet
weary garden
#

parsed my first Python program \o/

spark magnet
#

!ot is the place

fallen slateBOT
weary garden
#

gods are off topic

spark magnet
coral drift
#

but god's advanced fam

weary garden
#

because of the way folding works

flat gazelle
#

@coral drift please keep on topic

coral drift
#

which channel fam, there are too many

flat gazelle
#

!ot one of the off topic ones

fallen slateBOT
grave jolt
#

x: set[int] = set()
orpy
x = setint


2: ```py
x: list[int] = []
``` or ```py
x = list[int]()
```?
coral drift
#

i need to make a face detection thing from video

#

how can i start

peak spoke
#

mixing the hint and expression looks a bit weird to me

leaden gorge
#

what are good packages for sublime text?

weary garden
#

I wish sublime text supported RJSON

north root
raven ridge
grave jolt
#

Hm, right

#

But if we don't consider backwards compatibility?

sharp lance
#

It?

raven ridge
#

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.

grave jolt
#

it would be neat if the type was inferred

unkempt rock
#

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

raven ridge
unkempt rock
#

can we have a general discussion channel

#

or was that a bad thing

raven ridge
#

and the 3 off-topic channels

weary garden
#

I am having problems finding function calls in the grammar...

spark magnet
weary garden
#

but I cannot find where primary is used

spark magnet
#

power: await_primary; await_primary: primary

weary garden
#

ah yes

#

I followed it to disjunction and expression

weary garden
#

Let the sunshine, let the sunshine in.

severe lichen
#

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.

raven ridge
severe lichen
#

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.

raven ridge
#

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.

severe lichen
#

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?

raven ridge
#

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

severe lichen
#

Thanks! TIL, i didn't know about "all valid Python code is also valid Cython code"

raven ridge
# severe lichen I wonder which properties of python make it hard to compile to binary. Is it pos...

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.

unkempt rock
#

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?

radiant fulcrum
#

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

unkempt rock
#

i need it to show my intellect

#

and superiority and use bzzwords like cyberquantocryptography

grave jolt
unkempt rock
grave jolt
#

This channel is for discussing the Python language itself, mostly its future and past, its implementation and all that other meta-stuff.

knotty idol
#

Which is better for image classification PyTorch or Tensorflow?

gleaming rover
unkempt rock
#

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.

grave jolt
#

A set literal would be... {*()}, I suppose?

unkempt rock
grave jolt
#

but yeah, I've never seen list[int]() (maybe because it's only supported since 3.9? probably)

grave jolt
#

although that's probably noise

zenith topaz
#

It's meant for type hints

grave jolt
unkempt rock
#

Interesting, what about setint?

sacred tinsel
#

It didn't occur to me that we could now do x = set[int]() although then it won't make it into __annotations__

zenith topaz
#

list[int] is a type hint for a list with ints in it

grave jolt
#

well, yeah, I guess list[int]() is sort of an abuse...

grave jolt
zenith topaz
#
~/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.
grave jolt
#

are you sure you're on 3.9?

zenith topaz
#

3.10

#

nvm, I'm on 3.9.1, I switched away from 3.10 for some reason yesterday

severe lichen
#

Is setint different from set() in runtime now?"

grave jolt
#

no, same thing

unkempt rock
#

Probably you need mypy master build or something

#

Mypy always lags a bit behind

grave jolt
#

pyright supported patma before it got implemented

#

the dude has a time machine...

severe lichen
#

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
#

*args is a tuple, right?

#

!e

def f(*args): print(args)
f(1, 2, 3)
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

(1, 2, 3)
grave jolt
#

or do you mean destructuring?

#

!e

(x, *xs) = [1, 2, 3]
print(x, xs)
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

1 [2, 3]
grave jolt
#

hm, weird

zenith topaz
#

If I run with 3.10 specified it does allow subscripting list

severe lichen
#

Yeah, had a brain fart and mixed it up in my head.

grave jolt
#

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

wide shuttle
# grave jolt hm, weird

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.

grave jolt
#

Ah, I see

wide shuttle
#

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.

grave jolt
#

The tuple would take more memory than needed if you have items that you will remove from the end

terse orchid
#

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.?

wide shuttle
#

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

undone hare
#

Sometimes it will also be easier to use environment variables in production rather than .env files, depending on your setup

wide shuttle
#

Docker also has a separate secrets system and kubernetes has yet another way of providing secrets to containers

undone hare
#

Docker also has a separate secrets system
Do they? I never seen a secret store within Docker, that's interesting

wide shuttle
#

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.

terse orchid
#

I totally understand. Thanks.

wide shuttle
undone hare
#

Nice, cheers

terse orchid
#

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.

grave jolt
#

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.

terse orchid
grave jolt
#

well, json might be easier to work with (also has a standard library implementation)

terse orchid
#

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.

terse orchid
grave jolt
#

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

terse orchid
#

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 πŸ™‚

sacred tinsel
#

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 πŸ€·β€β™‚οΈ

grave jolt
#

well, yes

#

just make sure not to turn it into a marble machine

terse orchid
#

Okay, thank you so much.

jaunty veldt
#

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?

royal panther
#

hmm, anyone up for discussing creating a PEP for annotated assertions in the language (aka making pytest assertion rewrite unnecessary)

grave jolt
#

(not that I'm qualified to write a PEP, just curious πŸ™‚ )

royal panther
# grave jolt what do you mean by annotated assertions?

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

grave jolt
royal panther
#

thats one way of saying it

#

right now pytest does ast transformations to implement this

#

and it really should be part of the language

flat gazelle
#

so essentially assert should do something like a lisp quote, but also keep all the values.

grave jolt
#

yeah, a macro or something

visual shadow
#

What's the issue (if any) with the ast transformations?

grave jolt
#

I suppose that it's not the most straightforward thing...

#

although, where would it be useful besides assertions?

royal panther
#

its expensive, and hard to integrate with site-packages ^^

#

the feature i intent is specifically for assertions

visual shadow
#

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

grave jolt
#

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()
signal tide
#

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

peak spoke
#

literals will be created through direct bytecode instructions or constants created when it's compiled

pliant tusk
#

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

unkempt rock
#

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?

spark magnet
unkempt rock
spark magnet
#

if you don't mind me asking, why do you want to hide your source code?

unkempt rock
#

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

spark magnet
#

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.

unkempt rock
sour dragon
#

I don't understand how code obsfuscation will secure a web API

pliant tusk
sour dragon
#

Or why Python is your first choice for a program that is a compiled binary

spark magnet
#

@unkempt rock i guess i would start with one of those existing tools, and tweak it to be unusual.

sour dragon
#

Something something sun tzu underestimating the enemy

unkempt rock
#

any ideas on how i can keep it bellow 4MB? the source is 20kb

sour dragon
#

You have to distribute the Interpreter in your executable

#

No way around that really

spark magnet
#

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.

sour dragon
#

As much as I love python this is a poor use case for the language

spark magnet
#

i'm sure those tools have done what they could to keep it small.

sour dragon
#

Have you considered GoLang?

spark magnet
#

@unkempt rock 5Mb isn't a big deal these days usually

unkempt rock
#

ill explore my options with the methods i know, thanks for the help @spark magnet

brave badger
#

Uhhhhhhhh

#

!e Yikes, okay

print(23     .     bit_length())
fallen slateBOT
#

@brave badger :white_check_mark: Your eval job has completed with return code 0.

5
visual shadow
#

eyes twitch

rich cradle
#

It actually worked?

#

Whoa

wide shuttle
#

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()
)
pearl flume
#

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
#

what does vector do in c++

#

what is it used for

limpid marten
#

@cold rapids That's not really related to this channel, but it's there to support dynamic sized arrays.

severe lichen
#

@wide shuttle You're joking, but that's the exact pattern I've seeen in Pyspark.

wide shuttle
#

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)

flat gazelle
#

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)

severe lichen
#

That reminds me - aren't keyword arguments and factory method a thing in Java too?

limpid marten
#

I don't think so, no.

severe lichen
#

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?

flat gazelle
#
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
severe lichen
#

On one hand, custom operators are cool. On another - Perl.

flat gazelle
#

yeah, definitely not a feature I want in python, they do solve some things though

wide shuttle
#

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.

spark magnet
#

there are structural reasons that Python would have a hard time with fully custom operatorss

spark magnet
grave jolt
#

ah, right

#

well,

#

the issue here is operator precedence

undone hare
#

Incremental parsing is what is usually chosen for those type of languages

spark magnet
#

not just precedence, but the lexical question of what is an operator?

undone hare
#

Oh boy

grave jolt
grave jolt
gleaming rover
#

Scala’s custom operators are p dope

flat gazelle
#

@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
#

can someone help me with image handling?

#

PIL

flat gazelle
wheat beacon
#

ye was just seeking for more "advanced" help so my help request doesn't go to waste

#

although PIL is not that "advanced" imo

#

πŸ˜…

limpid forum
grave jolt
#

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

grave jolt
safe agate
#

bruh smh

trim schooner
#

Hey all how can I run two API's using request I want to run both at the same time

raven ridge
trim schooner
#

Cheer's bud!

visual shadow
weary garden
#

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?

pliant tusk
#

yea

#

python does have a @ operator that is used by some libs for matrix multiplication

weary garden
#

but the gramma say @ operator is for matrices

#

what happens if you use @ without such a library?

pliant tusk
#

i mean any class can define def __matmul__(self, other): ...

weary garden
#

k

pliant tusk
#

or __rmatmul__ or __imatmul__

weary garden
#

how pervasive is floor division across languages? is // mainly a python thing?

radiant fulcrum
#

not really a python only thing

weary garden
#

hmm, it seems to be a useful enough concept for me to make it a first class semantic concept

pliant tusk
#

ik that C has the function floor()

radiant fulcrum
#

it mostly depends on each language because alot use // as a comment and opt to use a method to perform floor division

weary garden
#

the actual syntax is less interesting as to the question of it being a common atomic operation

grave jolt
#

statically typed languages use / for both flooring and integer division, it seems

radiant fulcrum
#

depends on the lang

#

some things will apply the numerical bounds rather than necessarily flooring it explicitly

grave jolt
#

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

radiant fulcrum
#

I just like the semantics in python that floor dividing a float will still return a float bloblul

grave jolt
#

lol

weary garden
grave jolt
#

how will you handle chaining comparisons?

#

!e

print(3 > 2 > 1)
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

True
weary garden
#

not looked at that yet

radiant fulcrum
#

btw how are you planning to support the C api ?

#

or are you just not gonna do that bloblul

weary garden
#

what do you mean by C api?

radiant fulcrum
#

i mean python's c api

grave jolt
#

make an alternative FFI that will only allow writing extensions in JavaScript

weary garden
#

you mean how you specify an external C function in python?

grave jolt
#

yes

weary garden
#

yes I will be supporting that

#

I will be using libffi for ffi

grave jolt
radiant fulcrum
#

are you going to support the semantics the same e.g. allocations and reference counting

radiant fulcrum
#

but from what ive seen of it, its hell compared to python's bloblul

weary garden
#

I will be supporting everything that isn't specific to a particular Python implementation

grave jolt
#

and I mean... JS is faster than Python

spark magnet
#

Python's C API isn't "external C functions".

grave jolt
#

right, no, it's not the external functions

#

it's how CPython is structured so that C extensions can manipulate Python stuff, right?

weary garden
#

so what is "Python C API" then?

radiant fulcrum
spark magnet
radiant fulcrum
#

that and JS learnt alot from Python already bloblul

weary garden
#

no I will not be supporting anything that is specific to CPython

radiant fulcrum
#

yikes

#

No C module support for us sad

weary garden
#

Grown up languages aren't tied to a particular implementation

#

or even worse a particular version of a particular implementation

radiant fulcrum
#

bloblul You're saying that about a 30 year old language which became immensely popular with fields due to the C api

weary garden
#

does PyPy support these 700 CPython functions?

spark magnet
radiant fulcrum
#

it provides hooks for them yes

#

not that it needs them because it's still built of Cpython

#

but yeah what ned says

spark magnet
radiant fulcrum
#

you're product is dead to the python community from day one without the C api

radiant fulcrum
spark magnet
#

ok πŸ™‚

weary garden
#

where is this C API documented?

radiant fulcrum
#

3 second google mmLol

spark magnet
weary garden
#

no I will not be supporting that.

radiant fulcrum
#

rip

#

Ig yer system is stuck to basic python scripts

weary garden
#

however someone could create a compatability layer if they felt the need

spark magnet
radiant fulcrum
#

I dont think anyone would be dedicated enough to the whole system when they could just use the normal interpreter and reap the benefits

weary garden
#

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?

spark magnet
#

people will conflate that criticism.

weary garden
#

you mean some people might take it badly

spark magnet
#

marketing is about dealing with people. I can't change that.

radiant fulcrum
#

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

weary garden
#

I don't constantly step on eggshells

spark magnet
radiant fulcrum
#

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...

spark magnet
#

There's just no point in talking about "grown up" languages. Implement what you want. why the insults?

radiant fulcrum
#

database drivers etc....

weary garden
#

so this C API is this the PyPy compatibilty layer people keep mentioning?

radiant fulcrum
#

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

weary garden
#

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

radiant fulcrum
#

can i ask why though

#

like i still struggle to understand why

weary garden
#

because Python is popular

radiant fulcrum
#

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)

weary garden
#

as I said I might create that compatibilty layer but it isn't a priority given my primary use-case.

radiant fulcrum
#

what is your primary use case for this 'version' of python then

weary garden
#

one of several scripting languages that my toolkit will support

radiant fulcrum
#

okay ...pithink sure...

weary garden
radiant fulcrum
#

ive already seen that

weary garden
#

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

radiant fulcrum
#

well i guess we can just hope that your skill in implementing a language is better than your web ui skill bloblul

weary garden
#

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.

grave jolt
#

why not implement JS?

#

it seems to be a smaller language

radiant fulcrum
#

implementing JS for that thing would be way easier than implementing Python lol

weary garden
#

I am implementing JS

#

but I am doing Python first

spark magnet
weary garden
#

the reason why I am doing Python is simply down to its popularity

visual shadow
#

Yay for python!

grave jolt
#

isn't JS much more popular? basically every website uses JS

radiant fulcrum
#

nah

spark magnet
#

I understand that. Why talk about "grown up" languages? It's pointless aggression.

radiant fulcrum
#

they're actually incredibly close

visual shadow
#

Js did win out on SO dev survey

radiant fulcrum
#

and equally JS has two main language specs

grave jolt
#

well, it's not clear how to compare 'popularity' of languages...

weary garden
#

nedbat why keep bringing it up? the conversation has moved on.

spark magnet
grave jolt
radiant fulcrum
#

Im guessing NodeJS itself is probably less popular than Python

limpid forum
radiant fulcrum
#

ECMA 5 is likely to be as popular if not more due to browsers running it

visual shadow
weary garden
#

no nedbat is going back to my earlier, valid criticism of Python not being standardized by a recognized standardization body

radiant fulcrum
#

I mean "grown up" doesnt make any sense though bloblul

limpid forum
weary garden
#

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".

radiant fulcrum
#

So you wouldnt call JS, Java etc... "grown up" bloblul

weary garden
#

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.

visual shadow
#

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.

grave jolt
#

Python isn't defined in terms of its implementation, it's pretty clearly stated what's standard and what isn't

weary garden
#

this 700 function C API that uses CPython structures seems awfully implementaiton specific to me

visual shadow
#

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.

radiant fulcrum
#

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

visual shadow
#

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.

radiant fulcrum
#

but it removes a incredibly large amount of the eco system that exists and has been built around Cpython and the C api

weary garden
#

anyway I don't wish to ruffle any feathers so I am quite happy for the subject to change.

grave jolt
weary garden
#

and that is what I am doing in the first instance

peak spoke
#

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

weary garden
#

making an implementation that supports pure Python code

grave jolt
#

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.

visual shadow
#

Fair. The only heads up there is that pypy went there, and isn't seeing major adoption perhaps because of it.

radiant fulcrum
#

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

grave jolt
#

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.

weary garden
#

not an example

radiant fulcrum
#

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

blissful comet
radiant fulcrum
#

async was the right channel

weary garden
#

@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

radiant fulcrum
#

but you cant do that with Pure python because it needs to interface with the raw C api or some other systems level interface

limpid forum
weary garden
#

you will be able to call C functions from my Python implementation

radiant fulcrum
#

okay but who's going to implement the C functions to produce those 2D/3D games

weary garden
#

@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

radiant fulcrum
#

🀨

limpid forum
weary garden
#

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

limpid forum
#

the bindings would still need to be basically a full lib, so it can be used nicely

weary garden
#

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

limpid forum
#

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

weary garden
#

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?

grave jolt
#

yep

#

it can be redefined

#

e.g. in the Decimal object

weary garden
#

but I assume for normal default behaviour it behaves as expected; i.e. +-2 == -2

#

how do you invoke the evaluator in this channel?

grave jolt
#

only helpers+ can do that IIRC

weary garden
#

k

grave jolt
#

!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)
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

001 | Int(40)
002 | Int(41)
003 | Int(42)
weary garden
#

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

weary garden
oblique crystal
#

maybe i don't undertand what's "standartized"

grave jolt
#

Haskell has an "official standard" (The Haskell Report), but most useful libraries use GHC-specific extensions anyway, so

weary garden
grave jolt
#

What's the difference between an ISO standard and a non-ISO standard (like Haskell Report)?

weary garden
#

ISO is an internation standards organization that isn't just about programming languages

grave jolt
#

I understand

#

but I mean, what difference does it make

oblique crystal
#

ok but standard evolves over time too?

weary garden
#

"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

ISO

Covering almost every product, process or service imaginable, ISO makes standards used everywhere.

spark magnet
#

we should not start debating the value of standards....

grave jolt
#

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"

weary garden
#

@spark magnet why not?

spark magnet
#

because it's contentious and off-topic

weary garden
#

that is certainly an opinion.

spark magnet
#

i guess you either think it won't be contentious, or it is on-topic?

weary garden
#

I would say it is on topic for this channel; it is advanced meta.

heady slate
#

Why are you being so pushy?

#

like just listen

weary garden
#

possible future standardization of Python is certainly within the scope of "future of the Python programming language" - this channel's topic.

oblique crystal
spark magnet
heady slate
weary garden
#

if anyone is being pushy here it is nedbat. he cannot seem to tolerate anything he perceives as slightly negative regarding Python

heady slate
#

Hmmm well I don't think that is very true but I am gonna withdrawal myself from this conversation before anything bigger happens

spark magnet
weary garden
#

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.

torpid flax
#

anyone selling popcorn rn

spark magnet
#

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.

weary garden
#

you know what you are doing; you have done it on IRC, Usenet and now here. Stop obsessing over me as an individual.

gleaming rover
#

this is rapidly going off topic

#

I suggest we return to the applicability of monadic composition to Python

spark magnet
#

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?

weary garden
#

this is a technical forum so keep it technical not personal.

gleaming rover
weary garden
#

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.

spark magnet
#

can you show me where in this forum I have said that?

weary garden
#

you have done it in IRC and Usenet and the pattern is being repeated here

gleaming rover
spark magnet
#

or, show @summer lichen where I have.

grave jolt
# gleaming rover I suggest we return to the applicability of monadic composition to Python

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?

weary garden
#

yes, change topic is good; don't want ****show here

gleaming rover
#

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

grave jolt
#

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?

gleaming rover
grave jolt
#

wdym?

gleaming rover
grave jolt
#

I meant that a monad has kind type -> type

gleaming rover
#

yeah, it was a related article

grave jolt
#

In Python terms, it's a generic type parametrized by a single type

gleaming rover
#

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)

grave jolt
#

Maybe ASGI apps form a category?

#

that seems quite ridiculous lol

#

I should ask that on some mailing list on 01.04

flat gazelle
#

Start simpler and try to come with a way in which an Asgi app is a functor

grave jolt
#

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?

raven ridge
#

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.

grave jolt
#

(MicroPython technically isn't Python Python, right?)

raven ridge
#

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.

grave jolt
#

well, 1or 2 not working pretty much makes it useless /s

raven ridge
#

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.

weary garden
#

my value proposition is being able to use Python with my toolkit

pliant tusk
#

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

weary garden
#

no, Python will be one of several languages I will support via my language agnostic scripting engine.

pliant tusk
#

my second point still stands

#

any language implemented in neos will behave slightly off from the source language. That will confuse users (imo)

weary garden
#

that is not the plan; I intend to fully implement the language

pliant tusk
#

do you plan to implement undefined things?

#

like globals()['a'] = 1 setting the global variable a to 1?

weary garden
#

I do not plan on implementing any quirks of specific implementations

pliant tusk
#

actually that is a defined thing in python

#

as is eval, exec

#

when you get to C will you implement integer overflow?

weary garden
#

I will implement the semantics of C as defined by the C ISO Standard

pliant tusk
#

Ok, fair

pliant tusk
#

i corrected myself, that behavior is defined (afaik)

weary garden
#

I am not yet familiar with that area of Python; I only started learning the language on Friday

raven ridge
#

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?

weary garden
#

correct

raven ridge
#

Does your toolkit have users yet?

weary garden
#

nope

raven ridge
#

So your toolkit is your primary concern, but you're choosing to prioritize a Python implementation over it?

weary garden
#

the scripting engine is an integral part of the toolkit and Python will be the first scripting language I will support

raven ridge
#

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.

weary garden
#

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

raven ridge
weary garden
#

because people who know Python already will be able to do neoGFX scripting without too much hassle

raven ridge
#

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.

weary garden
#

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

raven ridge
#

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?

weary garden
#

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

raven ridge
#

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.

weary garden
#

I am interested in getting numpy to work tho as neoGFX will be good for data visualisation

raven ridge
#

Numpy will not work without the C API.

rich cradle
#

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.

raven ridge
#

Lots of numpy is written in Fortran.

weary garden
#

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.

rich cradle
spark magnet
#

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.

rich cradle
#

Oh, got it.

weary garden
#

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

rich cradle
#

Makes sense.

#

What are your priorities? And what are you willing to compromise on?

weary garden
#

I have lots of things with equal priority to do

raven ridge
#

If everything is high priority, nothing is.

weary garden
#

indeed but such is life

raven ridge
#

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.

weary garden
#

no I fully intend to monetize it; my initial market will be the space currently occupied by Qt

raven ridge
#

Why would someone choose neogfx over PyQt5?

weary garden
#

I am not familiar with PyQt5 but neoGFX will be cleaner, less bloated, less legacy cruft, faster and higher quality than Qt

raven ridge
#

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.

weary garden
#

it will also be CHEAPER

#

Qt commercial licences are expensive

raven ridge
#

That gives you an immediate captive audience: people using that language, who currently have no high quality graphics toolkit option.

weary garden
#

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

grave jolt
#

what semantic concepts would Haskell be able to reuse? I don't think there's a good mature GUI toolkit for Haskell

weary garden
#

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

raven ridge
weary garden
#

I am getting four things out of this exercice: 1) fun 2) challenge 3) learning new languages 4) possible pocket money

raven ridge
weary garden
#

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

raven ridge
#

The MRO perhaps. The behavior of super() without arguments, maybe. Reflected operators, perhaps.

spark magnet
#

len(x) --> x.__len__() is particular to Python

weary garden
#

the form maybe but not the underlying concept

raven ridge
#

Reflected operators are, afaik, specific to Python, though. I'm not familiar with another language with something similar, at least.

pliant tusk
#

python's function closures storing values is not something ive seen in most languages

weary garden
#

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.

pliant tusk
#

ie: py def foo(n): def bar(): return n return bar

spark magnet
pliant tusk
#

i just remember trying to do it in C and not being very successful

raven ridge
#

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.

weary garden
#

you can capture values by reference or value in C++ lambdas: I see little difference there

spark magnet
#

@raven ridge how about descriptors?

raven ridge
#

Ooh, that's a very good one.

pliant tusk
#

or another fun one, the fact that dunders can change at any time

weary garden
#

well I need to support self modifying code too

raven ridge
#

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.

signal tide
raven ridge
#

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.

spark magnet
signal tide
#

why would you ever want them to not do the same thing?

spark magnet
#

you do want them to do the same thing.

spark magnet
#

well, if add is commutative.

spark magnet
signal tide
raven ridge
spark magnet
#

the operands have to be switched

raven ridge
#

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__

signal tide
signal tide
#

do any other languages implement something like that or is it pretty exclusive?

raven ridge
#

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);
signal tide
#

right right

raven ridge
#

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.

signal tide
#

actually I had no idea operator overloading was a thing in c++

weary garden
#

C++ is great πŸ˜„

signal tide
#

it looks like that was one of the things left out from c[++] in java

raven ridge
#

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