#internals-and-peps

1 messages Ā· Page 137 of 1

deep bramble
#

I tried with queue.LifoQueue and it ended up being even slower

deep bramble
#

sure but without it, if it were only as fast as regular CPython, it would still be a way better choice because of the possibility to have that just in time compilation

verbal escarp
#

also, i don't see a realistic scenario where appending and popping from a list is the bottleneck

deep bramble
#

I do, I'm using a stack datastructure for certain things and I've used a list there, I will try collections.deque it may be better, I assume it's written as a C extension, but still, the performance benefit of that from PyPy is huge and it's a difference between running my program for 5 minutes vs running it for 40 seconds

#

this isn't just from the list operations, but it's a big part of it

timber dragon
verbal escarp
timber dragon
#

yea, but I would need to copy it in every project. I do not like so

deep bramble
verbal escarp
#

numbers?

deep bramble
#

let me try and make a coherent example to test things rather then running it for my project only, give me a sec

#

I'd say that this is a fairly significant difference

#

this is it with lists, just for comparison

verbal escarp
#

pretty big difference, i agree

deep bramble
#

for some reason, pypy is actually faster with a list here than a collections.deque, but I'd say that's a very insignificant difference and is within standard deviations

verbal escarp
#

well, it's not the list or deque that is slow, it's the for-loop, i think

#

PyPy is well known for optimizing loops and other repeated calls, so that's not really surprising

deep bramble
#

there is a big difference here too, but not as big

verbal escarp
#

if the algorithm didn't require a stack but rather an array, i'd propose to try to use numpy with numba

#

numba also is known to optimize loops very well

deep bramble
#

I'm not saying there aren't ways to improve the speeds with CPython, I'm just wondering why are we still using it if we could use something so much faster

verbal escarp
#

because of limitations in PyPy?

deep bramble
#

what exactly are it's limitations?

verbal escarp
#

exactly that - numpy and other extensions

sacred yew
#

aka the places where you usually want to go fast

verbal escarp
#

it's sad and i would love to agree with you

elder blade
#

Wait now I want to see the Cython comparison

verbal escarp
#

i mean the whole notion "why can't we just replace CPython with PyPy"

#

it's beautiful

deep bramble
#

(With no optimizations though)

elder blade
#

But again, Cython when popping and happening to lists won't speed up jack-shit because it used the Python API

#

So you're still as slow as CPython

#

That's the thing, it's not a fair comparison

#

If you have loads of computations then you can use Cython to bring that to pure C speed, but if you use the Python API a lot then you're still as slow as Python.

elder blade
deep bramble
deep bramble
elder blade
verbal escarp
#

i'd say it's doable, but it would probably require a company to step up and actually pay a couple of devs full-time to do it and be able to catch up to the level of CPython is..

deep bramble
elder blade
#

Oh I read that wrong

#

I thought you mentioned Cython in your opening statement

deep bramble
#

and I think it would be a very welcome change it may even bring many developers who left python simply because it was way too slow

#

I just wanted to know if there was any particular reason it's not currently happening, I'd think we would always choose to go for the better option, even if it meant spending some time by rewriting some things, if it brings such a huge improvements

peak spoke
#

There is the adaptive interpreter pep

flat gazelle
#

well, there is a project at microsoft to make python faster using bytecode level specialisation. It is not quite a JIT, since maintaining a JIT is a nightmare

#

especially with how many platforms python runs on

deep bramble
flat gazelle
peak spoke
#

CPython targeting a lot of platforms is definitely a concern for switching up the implementation

flat gazelle
#

it's not really an issue with most things since C is mostly portable. But a JIT requires generating machine code per platform

verbal escarp
#

we also have the "leaky internals" issue

deep bramble
flat gazelle
#

yeah, stack access being a documented and supported feature does have its issues

verbal escarp
#

many projects rely on specific behaviour exposed by inspect etc

deep bramble
verbal escarp
#

if PyPy can provide a similar API, it might be feasible, i'm not an expert though

elder blade
verbal escarp
#

maybe the idea of having sub-interpreters might help

#

if we had an API shared between interpreters, different parts could be executed by different interpreters

#

shrug

elder blade
#

I really don't understand the point, they sound like they suck

#

Because they don't yet bypass the GIL, you can't launch them unless you're using the C API and.. huh?!

#

I've read the PEP but I still left knowing as little as I did after starting reading

verbal escarp
#

don't ask me, i just read over the PEP a while ago and dreamed up the rest :p

#

at least that would make sense to me, kinda

#

like, using subprocess, but specifically only for python processes

#

then you could mix and match interpreters that are best optimized for different scenarios

elder blade
#

To me they just sounded like a weird mix of threads or something..

verbal escarp
#

probably i'm way off and it's nothing like i imagine ^^

main lynx
#

theoretically you can have a separate GIL for subinterp as long as the different interpreters don't touch the same objects

#

and have separate contexts e.g. imports of builtins etc.

lusty scroll
lusty scroll
#

well I thouhht they did

elder blade
elder blade
lusty scroll
#

yeah guess we use

import _xxsubinterpreters``` for now
lusty scroll
#

but thats pretty much the limit afaik

elder blade
#

Yeah but "almost", what does that mean?

#

Do they span over multiple cores?

lusty scroll
#
>>> import _xxsubinterpreters as sub                                              >>> interp = sub.create()                                                         >>> interp
InterpreterID(1)
>>> sub.run_string(interp, "import _xxsubinterpreters as sub; ch = sub.channel_create(); sub.channel_send(ch, str(7 + 7))")
>>> sub.channel_recv(sub.channel_list_all()[0])                                   '14'
#

if there's a better way to do 7 + 7 i'd love to hear it

elder blade
#

So that code now runs on another process/subprocess and can take care of another core?

lusty scroll
verbal escarp
lusty scroll
#

same process, but you can't access objects in one from the other. like each interpreter would have its own True, False, None

pseudo sun
#

Hey I just started learning python any tips ???

elder blade
#

Well- there is one use-case I can think of with like asyncio

#

You can isolate different parts of a user's code

#

So that a user can't accidentally block the main important event loop logic doing something special

lusty scroll
elder blade
#

But even then that seems niche? What's so weird to me is how it feels like I am supposed to find it exciting but I just truly don't get the buzz y'know

lusty scroll
#

well i didnt say so šŸ˜‚

#

only picklable objects could be communicated ig

charred pilot
#

how is this different from multiprocessing then?

lusty scroll
#

maybe it would be useful for running tests

lusty scroll
#

there's more issues.... not every module (even in the stdlib) is compatible

#

C modules have to use "multi-phase initialization" to work afaik

main lynx
#

multiprocessing has to copy IPC, sub-interps can transfer ownership of objects, zero-copy

#

theoretically

#

and it gets hairy when objects are in containers and you're transferring them

#

does it transfer children or copy?

lusty scroll
#

lmao

#

in a pickle for sure

main lynx
#

the dream of sub-interps is truly parallel Python threads

#

which is orders of magnitude more efficient than multiprocessing

#

and not having to eliminate GIL from the Python interp

#

but still having to carefully separate contexts

#

either diligently locking access to shared resources or transferring ownership of objects in the heap

#

basically "Python: Hard Mode"

#

though tbh i haven't looked at the proposed interfaces yet so hopefully it will be made easy..

#

as they mention in the PEP the goal of sub-interps is parallelization of tasks you would otherwise have to throw expensive multiprocessing at

#

it is 304x slower than the fastest C version and much of the cost is wrapped up in multiprocessing overhead

#

for a task that is in parallel doing some arithmetic on numbers

#

this is where sub-interps should have a lot of value

#

without having to ship or write extensions for parallelization (see: numpy)

surreal sun
#

Question - What are some of the best talks regarding how import works in Python and the nits and grits of it? Was Beazley's talk in Pycon 2015 good, or are there any other good talks on it?

gleaming rover
#

imagine a world where float is replaced with Decimal, just like how the default integer's size in Python grows arbitrarily at need.

#

would that be a net positive or negative?

stuck valley
#

positive

#

Hi, here from #esoteric-python . I'm curious to see how the ast module works and how I can use it for unusual stuff.

surreal sun
stuck valley
#

Thanks

surreal sun
#

Usually the entire process would be

#

Reader -> Lexer (Tokenizes) -> Parser (AST) -> Compiler (context-free grammar) -> Assembler (Bytecode) -> Interpreter

stuck valley
#

Okay

#

Now... how can I (ab)use this?

#

Can I change the ast?

prime estuary
#

You can, and that's what it's exposed to let you do.

#

The AST is a big tree of objects you can mess with, and then pass it back to compile() to get a code object.

surreal sun
stuck valley
#

Ooh

#

So... now can I change it to allow me to make new syntactic rules, or not?

surreal sun
#

But yeah, as long as it won’t raise a syntax error as soon as it runs

stuck valley
#

Damn syntaxerrors

surreal sun
#

If you’re getting syntax errors, you should work with import hooks

#

Yes one second

#

Though it’s in a package so

#

It’s a bit abstracted

stuck valley
#

okay

surreal sun
#

!pypi ideas

fallen slateBOT
surreal sun
#

ā€œā€

Usage
Suppose that you want to use function as a keyword in Python, to mean the same thing as lambda, enabling you to write

my_program.py

square = function x: x**2
print(f"{square(4)} is the square of 4.")
You can do this using an import hook. The simplest (but flawed) way to create such an import hook with ideas would be as follows:
from ideas import import_hook

def transform(source, **kwargs):
    return source.replace("function", "lambda")

import_hook.create_hook(transform_source=transform)

Then, you'd need to use it. Since there is already an example import hook that does this, we'll use it instead. All you have to do is instruct Python to add your import hook and it will be used from that point on. Something like the following.

Lets's call this 'loader.py'

from ideas.examples import function_keyword
function_keyword.add_hook()

import my_program
and then run
python loader.py
So, my_program.py , and any other module that could be loaded by it would recognize that function is a valid alternative to lambda.
Many more examples can be found in the documentation, including a better way to create such an import hook and information about a console (REPL) that supports code transformations.
ā€œā€

#

This uses an import hook, however it’s within the explanation of a package so it’s abstracted

stuck valley
#

okay, thanks

#

I'll look into how it works

vale nest
#

Anyone API Developer Is Here?

hybrid quiver
#

What are the best GUI modules for python

#

Other than tkinter

raven ridge
#

It's off topic for this channel, but it's what that channel is for

elder blade
visual shadow
#

Negative. Floats are fasttttt

#

It's a very acceptable tradeoff when trying to number crunch

flat gazelle
#

I would like fractions by default for rationals and floats as a manual "gotta go fast" switch like lisp/raku

visual shadow
#

Fractions are probably a lot safer than decimals

#

I'm imagining 1/3 kind of scenarios with decimals

#

That would be...not fun

flat gazelle
#

yeah, decimal is quite specialised for currency etc

gleaming rover
#

okay, maybe not decimals, but just a non-native real number type

#

my PoV is more like…with something as high level as Py you want to hide the fact that ints and floats are imperfect concretions of mathematical abstractions, right

#

and we already do that with int; why not with the real number equivalent?

flat gazelle
#

ye, I agree with the sentiment. It is one of the things that makes lisps feel really nice to use

gleaming rover
gleaming rover
#

like functionally what is it about decimals that you think is less ergonomic than fractions

visual shadow
#

basically if you want precise calculations instead of current float implementation, then any division that would have led to 1/3 type of floats now instead lead to a ballooned up decimal that is going to impact every calculation it's contributing to from that point on

#

side note, i can see your POV and it makes sense to me. i suppose "expecting" something like numpy to deal with when you want calculations to be fast feels a bit like chicken and egg. numpy couldnt have existed without python first right, and then that means you essentially had to ship a language that was incapable of representing floats at all. in this, something about it all feels...wrong, im not quite sure what. Like, ints are still a great abstraction over machine ints, because as long as they align, they align just fine.

#

but maybe it's fine, im not sure yet

gleaming rover
#

Like, ints are still a great abstraction over machine ints, because as long as they align, they align just fine.
true

#

I didn’t account for that

#

I’m writing my parser now and I was just thinking

#

do I really need floats…?

flat gazelle
elder blade
#

Just have any division result in fractals, and hard-coded 0.3 uses decimals

flat gazelle
#

now, one thing I do want is the default repr of a rational to be a decimal number rather than a fraction

gleaming rover
jagged portal
#

Hey guys can I use whatsapp and ADB modules at the same time to automatically send a message on android on whatsapp

verbal escarp
#
  1. probably 2) what's ADB? 3) how is that related to python 4) how is that on-topic for this channel?
verbal escarp
verbal escarp
verbal escarp
#

the python workflow strongly tends to be "prototype quickly to get a working proof-of-concept, then optimize and restrict" - removing float would make it much harder to convert from python code to numpy etc

stuck valley
#

I made something like that before

verbal escarp
#

i made something "like that" before, too, but the ast transform makes it so much more powerful

stuck valley
#
std,cout=type('',(),{'__getitem__':lambda self,name:type('',(),{'__lshift__':lambda self,data:(__import__('sys').stdout.write(str(data)),self)[1],'__repr__':lambda self:''})()})(),0

#include <iostream>

a=2
b=502
std[::cout] << a << b;
#

will read

verbal escarp
#
@pipes
def pretty_pipe():
    print (
        range(-5, 0)
        << map(lambda x: x + 1)
        << map(abs)
        << map(str)
        >> tuple
    )  # prints ('4', '3', '2', '1', '0')
#

that's something you can't do with that approach

stuck valley
#

sith magic

#

is it all in __init__.py?

verbal escarp
#

yup

#

it's only a very small piece of code actually, you can copy&paste

stuck valley
#

however this only works for stuff which is syntactically valid

verbal escarp
#

yeah, it needs to survive the parsing step

#

you can't change the syntax via the AST, but you can change any behaviour after

#

afaik pytest also uses AST transform

flat gazelle
#

floats for irrational numbers, fractions for rational numbers

verbal escarp
gleaming rover
#

interop might be complicated?

flat gazelle
gleaming rover
#

is it simple to statically determine if an operation will produce a rational or irrational number?

#

I'm thinking of like 4 ** 0.5-equivalent?

verbal escarp
gleaming rover
flat gazelle
#

ye, I feel like we are too quick to tolerate defaulting to incorrect math for rationals

flat gazelle
verbal escarp
#

at that point i'm thinking bytes vs. str

stuck valley
#

so if I want to chance the syntax that's more complex

#

say I want to add print_keyword

#

(hypothetically)

verbal escarp
#

what if fractions are used for transmission and floats internally, just like bytes and str

gleaming rover
#

like serialisation?

verbal escarp
#

sending data, storing data

#

yes

gleaming rover
#

why not strings

verbal escarp
#

too much overhead?

gleaming rover
#

okay, I guess it depends on whether what you have tends to be rational?

flat gazelle
#

str doesnt use bytes internally to my knowledge (or well, no more than literally any other type does)

gleaming rover
elder blade
gleaming rover
verbal escarp
flat gazelle
#

oh, you mean like you serialise str into bytes. But how is that related to float vs fraction

verbal escarp
#

yes

#

well, if you think about it, fractions are better suited for serialisation because, ideally, it's precise, while floats are system-dependent

flat gazelle
#

but that doesnt solve the important issue, which is that floats have incorrect results

#

regardless of system

verbal escarp
#

no, but then we would default to fractions for serialisation and the user could decide whether or not to use floats for speed or not

#

(and, in case of numpy, which kind of floats, without losing any information)

#

my guess: no

flat gazelle
elder blade
#

Yes, because you need to support it at the runtime.

verbal escarp
flat gazelle
#

You do want to keep floats as they are a better representation of reals than fractions or decimals

verbal escarp
#

complex?

flat gazelle
#

using complex for reals would be odd IMO

verbal escarp
#

yes

flat gazelle
#

but ye, IG you could replace all floats with complex without much effort

lament sinew
#

People overestimate the impact floating point precision, it's just a non issue in the vast majority of use cases.

#

even in areas that people think precision is important, like finance or engineering.

verbal escarp
#

i'll have to meditate over fractions for serialisation, it's an interesting idea i think

verbal escarp
lament sinew
#

It's such a myth that finance people need to use fixed precision reals.

verbal escarp
#

no, it's not

lament sinew
#

They'll either use ints or round floats around.

flat gazelle
#

afaik in finance it is so that you get correct rounding as you would get should a human do the math, not to be more precise

verbal escarp
#

the more transactions, the higher the impact of slight imprecisions - and then look at high frequency trading

flat gazelle
#

and engineers don't need more than a doubles worth of precision due to just how much the 14 or so digits actually are IRL

verbal escarp
flat gazelle
#

you can do just about all math with floats, but you have to be mindful that the computer isn't doing rational math, but taking a pretty good guess at rational math

#

which I don't like, since I just want to do correct rational math and use == between 2 rationals without having to think about the domains of my valaues

verbal escarp
#
NASA/JPL Edu

Earlier this week, we received this question from a fan on Facebook who wondered how many decimals of the mathematical constant pi (Ļ€) NASA-JPL scientists and engineers use when making calculations:Does JPL only use 3.14 for its pi calculations? Or do you use more decimals like say: 3.1415926535897932384626433832795028841971693993751058209749445...

#

40 decimal places

gleaming rover
flat gazelle
#

40 decimal places is afaik overkill, for rocketry you need 7 afaik.

#

40 is for radius of the universe to the precision of a hydrogen atom

verbal escarp
flat gazelle
#

it's more a matter of float errors being a low level detail that only makes programming harder

#

(unless you need performance)

#

and you do have to write your code in a way that accounts for these errors

#

even if the math itself is good enough for just about anything

verbal escarp
#

hypothesis taught me that lesson

lament sinew
lament sinew
flat gazelle
#

and I argue that it is worthwhile to use fractions instead of floats by default

#

as it leads to more predictable code that lies closer to how an abstract logical machine would handle the math

#

and the performance benefits of floats are not meaningful in enough cases to be worth making it the default

lament sinew
#

CPU architecture has been optimized to handle floating point operations for the last what? 40 years? I'd say using fractions as default is bad enough even if just for the amount of greenhouse gases their wide use over floats would entail.

#

I'm being hyperbolic but you get where i'm going

verbal escarp
#

CPUs aren't very optimized for floats, that's what GPUs are for

gleaming rover
lament sinew
#

no the point is the compromise between correctness and speed

spice pecan
#

Correctness and predictability, yeah

#

So that .1 *3 == .3

lament sinew
#

of course if correcness is you one and only criterion then fractions is the logical choice

#

my point is that it's a bad criterion

flat gazelle
#

in an algorithm where math forms a meaningful portion of CPU time, I would agree. But most code (at least the kind I write) is IO bound or CPU bound on string manipulation or searches. Not on non-whole number math.
correctness and ease of use is the thing I care about

#

whether adding 2 numbers is 10x slower doesnt matter when I add 2 numbers per web request

verbal escarp
#

and when you need to manipulate lots of floats, you're probably also using numpy, which requires you to specify the exact variant of floats you want

spice pecan
#

Python is not commonly used for performance-critical number crunching, and in places where it is, it's done via an extension like numpy over python itself. I think the point int already abstracts away the range limitations, float should also abstract away imprecision is very fair

gleaming rover
gleaming rover
gleaming rover
#

I was thinking Real (since I wanna use capitalised words for type identifiers)

spice pecan
#

Well yeah, given that such a change does occur, it shouldn't be called float anymore

flat gazelle
#

raku calls it Num

#

and a fraction is Rat

gleaming rover
flat gazelle
#

no, Num is specifically floats

spice pecan
#

real/fraction/rational/etc would be more than fine

gleaming rover
spice pecan
#

A unified number type would also be convenient

gleaming rover
#

then what's int?

#

Int?

flat gazelle
#

ye

gleaming rover
spice pecan
#

That's one thing I don't hate about it tbh, and I feel like it would suit the whole number is number rhetoric

flat gazelle
#

you cant always do that since you do indeed sometimes want floats for perf, even in python

visual shadow
#

i hate to be "that" guy but practicality beats purity.

gleaming rover
flat gazelle
#

but raku for example lets you use any numeric type as a number in any place due to implicit conversions

visual shadow
#

hehe. the problem is, ultimately if you truly want a system that's capable of handling all scenarios nicely, you have to compromise with the physical limitations of the hardware we have

spice pecan
#

I don't propose getting rid of floats, but I could definitely get behind making Fraction either the default, or at least easily accessible

gleaming rover
visual shadow
#

would love to hear what kind of performance implications that would have. it seems like the most decent compromise if you wish to avoid floats

lament sinew
#

I still see no good argument for fractions as defaults, you keep saying "correctness and ease of use" but fractions offer nothing more than floats already offer in that regard, except in the most specialized fields. While floats offer significantly better performance. So far it sounds like it's a purely aesthetic desire.

visual shadow
#

why would fractions not offer more than what floats already offer? floats are imprecise

flat gazelle
#

you can use equality on fractions and get correct results

#

you can also hash fractions and get correct results, therefore you can put them in a set or as dict keys

visual shadow
#

0.1 + 0.2 would genuinely be equal to 0.3 if it was all backed by fractions

flat gazelle
#

0.1 + 0.2 is equal to 0.3, most implementers just compromise for ease of implementation and performance and accept the wrong result

jagged portal
#

Can I use ADB and whatsapp toolkit together for android

flat gazelle
#

I don't think it is a sensible tradeoff

visual shadow
gleaming rover
#

does any other language do Python’s arbitrary width int thing

visual shadow
#

probably, lets find out

jagged portal
visual shadow
#

Some programming languages such as Lisp, Python, Perl, Haskell and Ruby use, or have an option to use, arbitrary-precision numbers for all integer arithmetic. - wikipedia. im not sure which ones out of those have it as default

flat gazelle
#

most lisps, ruby, perl, raku, haskell default to it

#

JS, java, kotlin, C# have it as an opt in

visual shadow
#

js has ints? i thought it was still doing that random "everything is a float" thing

gleaming rover
gleaming rover
#

or BigInteger, can’t remember which

visual shadow
#

i see, never heard of it before.

flat gazelle
#

lisps and raku also use fractions by default

gleaming rover
elder blade
#

Lol

#

!e ```python
print(0.1 + 0.2 == 0.3)

fallen slateBOT
#

@elder blade :white_check_mark: Your eval job has completed with return code 0.

False
surreal sun
#

Damn, how are you adding all this new stuff? I’m guessing you know how to edit C code

verbal escarp
#

was that an ast manipulation? šŸ˜„

#

but 0.1 + 0.2 == 0.3 => False really should be a good reason why we should default to fractions

#

it's so in your face that any school child will say "wtf, python is cool, but this is all wrong!"

#

and it's really hard to explain to a beginner

#

i wonder how those are implemented in calculators

paper echo
#

I don't know if it's particularly difficult, but it's definitely a learning moment where the student realizes computers are not magic

#

And then they realize how pretty much everything in the world is built on hacks that are built on kudges that are built on design decisions that made sense 45 years ago but probably don't make much sense today

verbal escarp
#

well, imagine a teacher in 4th grade maybe who wants to teach their kids about decimals and thinks it might be a good opportunity for a first contact with python to experiment

#

the kids just learned about fractions and now nothing works as expected

#

that's probably not a good learning experience

paper echo
#

python 4: / on ints returns a Fraction

boreal umbra
#

I just saw code like this for the first time:

    with NpyScpWriter(
        output_dir / "norm",
        output_dir / "norm/feats.scp",
    ) as norm_writer, NpyScpWriter(
        output_dir / "denorm", output_dir / "denorm/feats.scp"
    ) as denorm_writer, open(
        output_dir / "speech_shape/speech_shape", "w"
    ) as shape_writer, open(
        output_dir / "durations/durations", "w"
    ) as duration_writer, open(
        output_dir / "focus_rates/focus_rates", "w"
    ) as focus_rate_writer:

I guess there's an audience for the 3.10 changes to with statements after all.

verbal escarp
paper echo
#

if only i could use 3.10 at work, i'd get rid of so many ExitStacks in my tests

paper echo
#

plus, the reality is that computers use floats and floats are imprecise

verbal escarp
#

you missed the whole debate about fractions as default? šŸ˜‰

paper echo
#

no, i use lisp so you know i would love it

#

but i'm saying it's not really an indictment against python as a beginner-friendly language

pliant tusk
#
>>> from fishhook import * 
>>> @hook(int)
... def __truediv__(self, other):
...     return Fraction(self, other)
... 
>>> 1/2
Fraction(1, 2)
>>> print(1/3)
1/3
>>> ```
paper echo
#

but yeah sure it'd be a nice feature for newbies, until they try to do real-number stuff with rationals and can't

verbal escarp
#

fishhooks and forbidden fruits.. not sure whether to love or hate those šŸ˜„

lusty scroll
#

we're back on with the fractions i see

#

there's got to be a hundred packages out there that do fractions

#

oh, i missed that it's being added with a hook, that's actually pretty cool

#

what would be a reason to override the built-in getattr -- I noticed its looked up many times in the interpreter

#

wonder if it's used to look up simple names in source or only when getattr(...) is literally being used

static bluff
#

If I wanted to build a game, which UI engine do you all recommend?

#

Unity?

verbal escarp
#

what kind of game?

unkempt rock
#

hi i need a little help im new to python and im experimenting around for fun, this is my code so far:

import itertools
import string
import datetime
characters = string.ascii_lowercase + string.digits
for i in range(len(characters)):
    for j in itertools.permutations(characters, i):
        x = datetime.datetime.now()
        date = "[%s-%s-%s/%s:%s:%s]" %(x.year, x.month, x.day, x.hour, x.minute, x.second)
        print(date,"[COMBINATION] :","".join(j))

and i've been noticing that this code actually doesnt do a full combination betwen all the characters, so it does go through all them like abd ab3 a3s 9as etc.... but, it never uses the same character in the same combination. like aba, or acc, it skeps to the next character instead so it goes abb, but that doesnt work either so it does abc, so it skipped from aba to abc. how do i fix this? itertools.combination doesnt work either since .combination skips all the numbers after the 2 digit combinations.

static bluff
#

It'd be a 4x style strategy, mostly a 2d interface overlaid on a 2d hex grid

#

But I want to implement a 3d geodesic for a certain dimension of it

verbal escarp
#

you might want to use combinations_with_replacement

native flame
#

has there been any discussion about built-in syntax for named tuples?
i really liked how julia does it:

julia> tup = (a = "aa", b = 2, c = 3.4)
(a = "aa", b = 2, c = 3.4)

julia> tup[2]
2

julia> tup.a
"aa"
elder blade
#

I... i wouldn't hate ('a': 'aa', 'b': 2, 'c': 3.4) I guess

native flame
#

hm

grave jolt
#

but

#

why not just make a dict?

native flame
#

named tuple still allows indexing

#

also immutable and hashable

#

i also feel like named tuples represent heterogenous records more naturally

unkempt rock
#

Code:

import itertools
import string
import datetime
characters = string.ascii_lowercase + string.digits
for i in range(len(characters)):
    for j in itertools.product(characters, repeat=i):
        x = datetime.datetime.now()
        date = "[%s-%s-%s/%s:%s:%s]" %(x.year, x.month, x.day, x.hour, x.minute, x.second)
        print(date,"[COMBINATION] :","".join(j))

Atm its printing all different possible combinations between the 36 letters and numbers ive provided, but i want to compare the combinations until it matches a variable, for example if i have a variable x = "kasd8" and i want to check each of every combinations made until it matches, how can i do this?
Im going offline now so either tag me or dm me with the info i need so i can read it later on, ty.

verbal escarp
#

is there a tidy way to unload extension modules? looking at https://bugs.python.org/issue34309 i'm thinking of a __del__ hook for the ProxyModule so that you can do del(mod) and safely unload a use()d module in order to re-use it

#

since we talked about it the other day, maybe subinterpreters could work?

#

i'm imagining loading the package into a subinterpreter and simply kill the whole thing on del

#

or maybe run the whole package in its own actual python interpreter as subprocess and then communicate via stdin/out

main lynx
#

having trouble imagining either approach being worth the cost

#

afaict to send anything more complex than a handful of primitive types to/from a subinterp you have to pickle to a string

#

subprocess same story, except have to pickle (or otherwise encode) everything to byte stream

#

i should say the thing i'm having trouble imagining is the use case

elder blade
#

That seems extremely hard though

main lynx
#

that's interesting, not familiar enough with import mechanics to know if there's an easier way than subinterps

#

naive thought is import module in subinterp, pickle all the globals and send them back on a channel šŸ˜„

#

but i would be very surprised if that worked against any extension (if at all)

#

!e

import _xxsubinterpreters as interpreters
import pickle

code = """
import _xxsubinterpreters as interpreters
import math
import pickle
interpreters.channel_send(channel, pickle.dumps(math.__dict__))
"""

interp = interpreters.create()
channel = interpreters.channel_create()
interpreters.run_string(interp, code, {"channel": channel})
math = pickle.loads(interpreters.channel_recv(channel))
print(math)
print(math["sqrt"](2))
fallen slateBOT
#

@main lynx :white_check_mark: Your eval job has completed with return code 0.

001 | {'__name__': 'math', '__doc__': 'This module provides access to the mathematical functions\ndefined by the C standard.', '__package__': '', '__loader__': <_frozen_importlib_external.ExtensionFileLoader object at 0x7f8d9fe11e20>, '__spec__': ModuleSpec(name='math', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f8d9fe11e20>, origin='/usr/local/lib/python3.9/lib-dynload/math.cpython-39-x86_64-linux-gnu.so'), 'acos': <built-in function acos>, 'acosh': <built-in function acosh>, 'asin': <built-in function asin>, 'asinh': <built-in function asinh>, 'atan': <built-in function atan>, 'atan2': <built-in function atan2>, 'atanh': <built-in function atanh>, 'ceil': <built-in function ceil>, 'copysign': <built-in function copysign>, 'cos': <built-in function cos>, 'cosh': <built-in function cosh>, 'degrees': <built-in function degrees>, 'dist': <built-in function dist>, 'erf': <built-in function erf>, 'erfc': <built-in function erfc>, 'exp': <built-in function exp>, 'ex
... (truncated - too long)

Full output: https://paste.pythondiscord.com/uxefoqodev.txt?noredirect

main lynx
#

you can't marshal or pickle a module, but you can its __dict__

main lynx
#

can't pickle numpy tho

<string>:3: UserWarning: NumPy was imported from a Python sub-interpreter but NumPy does not properly support sub-interpreters. This will likely work for most users but might cause hard to track down issues or subtle bugs. A common user of the rare sub-interpreter feature is wsgi which also allows single-interpreter mode.
Improvements in the case of bugs are welcome, but is not on the NumPy roadmap, and full support may require significant effort to achieve.
Traceback (most recent call last):
  File "/home/matt/src/spectral-norm/subinterp_import.py", line 13, in <module>
    interpreters.run_string(interp, code, {"channel": channel})
_xxsubinterpreters.RunFailedError: <class 'AttributeError'>: Can't pickle local object 'setquit.<locals>.Quitter'
#

even for modules that do support sub-interpreter, exporting all of the functions seems complicated

#

potentially you could break down the AST and ship that back through the channel, and now we're getting into some evil magick

#

keeping the module imported in the sub-interpreter and abstracting the interface through channels would be prohibitively expensive

verbal escarp
#

hmm.. that depends

#

taking my idea from the other day and truely use a subprocess with an optimized python implementation for this purpose..

#

we could use a totally optimized interpreter for the numeric processing and ship the input/output back and forth to the generic cpython

#

basically use cpython as master

#

might come with some nice performance benefits and allow real and clean unloading/reloading

main lynx
#

i don't understand, competing with numpy running everything through IPC?

verbal escarp
#

not competing, delegating

main lynx
#

numpy already has multiple backends for parallelizing

#

out of the box it will use all your cores

verbal escarp
#

yeah, but for instance i've had a case where numba trumped numpy performance-wise, JIT-ing a nice and clean for-loop vs. numpy vectorization

#

so, maybe there's a python interpreter that could do that out of the box but isn't as nice for general purpose usage like cpython?

main lynx
#

mypyc would seem to qualify

verbal escarp
#

sounds good

#

question remains how to communicate with it

main lynx
#

the purpose of this is being able to load and unload specific versions of modules?

verbal escarp
#

extension packages, yes

#

not single modules

#

single modules i got pretty much covered, but isolating whole package is much more difficult

main lynx
#

if sub-interps/subprocs really are the hammer for this nail, figuring out how to serialize the entire import seems more ideal than serializing every call-in

verbal escarp
#

i got nothing ^^

#

hacking with subprocesses isn't my domain

main lynx
#

is really like working with any data stream, "can i turn this into a bytestream, and decode it on the other end?"

lusty scroll
#

we need something much more powerful than pickle

#

dill perhaps

verbal escarp
#

Dill (Anethum graveolens) is an annual herb in the celery family Apiaceae. It is the only species in the genus Anethum. Dill is grown widely in Eurasia, where its leaves and seeds are used as an herb or spice for flavouring food.

lusty scroll
#

yes that dill šŸ˜‚

verbal escarp
#

šŸ˜„

lusty scroll
#

on the module unloading issue, why is the id() the same even after deleting and recreating the _sqlite3 module? for example _sqlite3.Error
even manually calling dlclose in between and verifying the .so gets unloaded, the static types are still at the same address when importing a second time

spice pecan
#

Could be an optimization, python often places things in recently freed memory

#

I don't think it's that unreasonable to assume that it just happened to repopulate the same blocks again

lusty scroll
#

is there a way to check that they're actually freshly initialized blocks?

elder blade
#

Doesn't the GC allow you to see who has a reference to an object?

lusty scroll
#

i guess i could write garbage over them šŸ˜…

#

gc.get_referrers ?

spice pecan
#

Well, I can suggest a way to check if it actually reloads the module

#

Extremely unorthodox, but still

#

Use ctypes to write garbage and see if something breaks

lusty scroll
#

what could go wrong

spice pecan
#

Exaaaaaactly

verbal escarp
#

i love it when a plan comes together snicker

lusty scroll
#

how to find referrers without holding a reference? šŸ‘€

spice pecan
#

uh

#

Weakre... no, wait

#

Actually, weakref might work

pliant tusk
#

loop through gc.get_objects?

#

then call get_referrers on each and call id on each obj and see if it equals the held address

spice pecan
#

Or that, yeah

pliant tusk
#

can i ask why tho?

spice pecan
#

They're reloading the sqlite3 module, but the memory addresses seem to persist

#

So they're wondering if it does get re-initialized in the same space or if it doesn't get reinitialized

#

At least that's my understanding

lusty scroll
pliant tusk
#

unlikely

verbal escarp
#

i wonder if sqlite3 is a good test for that after all

#

it may be built in too deeply

spice pecan
#

Unload built-ins brainmon

pliant tusk
#

nah python is bad at fully freeing any thing

#

cause all classes keep a reference to their subclasses

lusty scroll
pliant tusk
#

!e py for i in range(10): class a():pass del a print([cls for cls in object.__subclasses__() if cls.__name__ == 'a'])

fallen slateBOT
#

@pliant tusk :white_check_mark: Your eval job has completed with return code 0.

[<class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>, <class '__main__.a'>]
spice pecan
#

That's not very free

lusty scroll
#

after doing import _sqlite3 there are already 15 things keeping references to it?

#

i can think of 2...

elder blade
pliant tusk
#

yea python has a lot of cross caching for speed

#

and a lot of it is low cost enough that its left till program close

elder blade
#

Tl;Dr Python says Fuck you and your use-case haha

lusty scroll
#

theoretically one could loop through get_objects() setting attributes to None until there are no more references?

elder blade
verbal escarp
#

well, unloading/reloading a builtin never was the actual use case

#

there's not really a point to that imo

#

extensions like numpy on the other hand..

pliant tusk
#
_del = delattr
_imp = __import__
import builtins
for i in dir(builtins):
    _del(builtins, i)

sys = _imp('sys')
del _del, _imp
sys.meta_path.clear()
sys.modules.clear()

# everything here is broke```
elder blade
#

Will multi-phase-setup mess with that?

lusty scroll
#
>>> len(gc.get_referrers(_sqlite3))
15
>>> del sys.modules["_sqlite3"]
>>> len(gc.get_referrers(_sqlite3))
14
``` 1 down
verbal escarp
#

hrhr

lusty scroll
#

its the stuff in its module

#

and some unknown list

#

so this clearly indicates nothing was reloaded, correct

spice pecan
#

Allegedly, yes

elder blade
#

So does it have circular references?

lusty scroll
#

i knew functions have __globals__, but where are they storing the module itself?

elder blade
#

What if you force the GC to run?

lusty scroll
spice pecan
#

Yeah, it remains alive after getting removed from sys.modules and its name deleted

elder blade
#

What does gc.get_referrers() return?

spice pecan
#

It gives me a list of 15 referrers, actually

#

Most of which are from sqlite3?

#

Interesting, considering _sqlite3 was imported

elder blade
spice pecan
#

Objects

#
[[None, <module 'sys' (built-in)>, <module 'builtins' (built-in)>, None, None, None, None, <module 'io' (built-in)>, None, None, <module 'winreg' (built-in)>, None, None, None, None, None, None, None, None, None, None, <module '_datetime' (built-in)>, None, <module '_sqlite3' from 'C:\\Users\\FarmArt.DESKTOP\\AppData\\Local\\Programs\\Python\\Python310\\DLLs\\_sqlite3.pyd'>], <built-in function adapt>, <built-in function complete_statement>, <built-in function enable_callback_tracebacks>, <built-in function enable_shared_cache>, <built-in function register_adapter>, <built-in function register_converter>, <class 'sqlite3.Row'>, <class 'sqlite3.Cursor'>, <class 'sqlite3.Connection'>, <class 'sqlite3.Node'>, <class 'sqlite3.Cache'>, <class 'sqlite3.Statement'>, <class 'sqlite3.PrepareProtocol'>, <built-in function connect>]```
lusty scroll
#
[
  [None, <module 'sys' (built-in)>, <module 'builtins' (built-in)>, None, None, None, None, <module '_io' (built-in)>, None, None, None, None, None, None, None, <module 'readline' from '/data/media/0/src/python3/build/build/lib.linux-aarch64-3.11/readline.cpython-311-aarch64-linux-gnu.so'>, None, None, None, None, None, None, None, None, None, None, None, <module '_sqlite3' from '/data/media/0/src/python3/build/build/lib.linux-aarch64-3.11/_sqlite3.cpython-311-aarch64-linux-gnu.so'>]
 <built-in function complete_statement>,
 <built-in function connect>,
 <built-in function enable_callback_tracebacks>,
 <built-in function enable_shared_cache>,
 <built-in function register_adapter>,
 <built-in function register_converter>,
 <class 'sqlite3.Row'>,
 <class 'sqlite3.Cursor'>,
 <class 'sqlite3.Connection'>,
 <class 'sqlite3.Statement'>,
 <class 'sqlite3.PrepareProtocol'>,
 <built-in function adapt>,
  # the __main__ dict im using 
]

yeah

spice pecan
#

The first referrer seems to be a list

#

That also contains sys, builtins and a bunch of Nones

elder blade
#

Why does None hold a reference to _sqlite3 šŸ˜‚

spice pecan
#

No, no

#

None just happens to be in the same list

#

That holds a reference to _sqlite3

#

Let me remove it from that list

lusty scroll
#

13!

elder blade
#

šŸ‘

spice pecan
#

It's all functions

#

And a few classes from sqlite3

#

Time to run dir a bunch of times

lusty scroll
spice pecan
#

Runs nicely so far

elder blade
#

so far šŸ‘€

lusty scroll
#

where is the module stored in a function, though, I'm genuinely baffled

spice pecan
#

It's not stored as an attribute on classes either

lusty scroll
#

certainly soundes like a circular reference

spice pecan
#

perhaps the functions are used as closures, and that's where the dangling reference comes from?

elder blade
#

But does sqlite3 exist in sys.modules?

spice pecan
#

Nope

#

KeyError

lusty scroll
#

need a Ctrl+F for object graphs

#

wait

#

its __self__

spice pecan
#

Well, all I can say is, adapt only has _sqlite3 as a referent

spice pecan
#

OH

#

Attribute is not writeable

lusty scroll
#

but when you such functions, its not passed as an argument ?

spice pecan
#

Uh

#

That seems to be a circular reference

lusty scroll
spice pecan
#

Running get_referrers on the function seems to give _sqlite3 as one of the results

spice pecan
#

How about we give one name to it

#

Overwrite the refcount to 1

#

And remove that name?

#

That should trigger destruction

lusty scroll
#

overwrite the refcount? o.O

spice pecan
#

It's stored as an int on the object, so yeah

elder blade
#

?!

spice pecan
#

I did that at some point, just gotta remember the offset

#

Or look it up in the sourcecode, but that's not fun

elder blade
#

We're in for a ride here ladies, gentlemen and non-binary..

lusty scroll
#

its before the object i think

pliant tusk
#

refcount is offset 0

spice pecan
#

Oh

#

That makes things easier

pliant tusk
#

so c_ssize_t.from_address(id(obj)).value = 1 sets refcount to 1

spice pecan
#

Yup

#

Gonna try that

verbal escarp
#

that most certainly is resulting in a demon entering this plane of existence..

lusty scroll
#

i thought ob_type was at offset 0?

pliant tusk
#

ob_type is the second 8 bytes

lusty scroll
#

ohh

verbal escarp
#

what have i done >.>

spice pecan
#

Eyyy

#

The weakref died after that

#

I assume we broke things

lusty scroll
#

that is the #, wow

spice pecan
#

now, if only I was smart enough to keep a reference to it

#

And crash the interpreter

lusty scroll
#

but get_objects still returns 13 things?

spice pecan
#

Oh

lusty scroll
#

*get_referrers

unkempt rock
#

Wsg bru

spice pecan
#

Try accessing an attribute

lusty scroll
#

it's traversing?

spice pecan
#

Fun things are happening

elder blade
unkempt rock
#

@worldly venture wtf your tag 😭

spice pecan
#

I'll try again in a new session

unkempt rock
#

bros badges are fire asf

elder blade
lusty scroll
#

it let me set ["__self__"] = None

#

thats not the same is it

spice pecan
#

I just tried to access _sqlite3 after manipulating it into getting finalized

lusty scroll
#

fail, that was my __main__ dict

spice pecan
#

At first I got the repr for a method-wrapper of io.Bytes.write, and a couple seconds later a segfault

lusty scroll
#

disable gc

spice pecan
#

The refcounting is a different mechanism IIRC

#

gc is specifically for circular references, refcount finalization bypasses it

lusty scroll
#

i think it's from allocation calling some GC "get memory" function, at least, thats what it looked like

#

mine crashed on tab completion

#

well that was fun, i guess i got my answer

spice pecan
#

We've brutally assaulted the interpreter

lusty scroll
#

sad but satisfied 🄲 🄲

lusty scroll
#

so why <built-in function> has a __self__ ??

spice pecan
#

Possibly refers to the module it's coming from?

#

Yeah

lusty scroll
spice pecan
#

So they were circular references

lusty scroll
#

well if we're trying to unload, I don't see how it would hurt to clear that __self__ attribute

#

if I can figure out how

#

so gc.get_objects / gc.get_referrers doesn't use refcounts too

#

seems like

spice pecan
#

The gc and the refcounts are two separate mechanisms, yeah

#

Oh

#

There's a recursive tuple there for some reason

#
>>> r[-6]
<built-in method register_converter of tuple object at 0x000001B270219D10>
>>> r[-6].__self__
(<NULL>, 'r', True, None)
>>> r[-6].__self__[0]
((...), 'r', True, None)```
#

Internals are kinda scary

surreal sun
#

Yikes

lusty scroll
#

even dill can't pickle a PyCapsule object, apparently

swift crag
#

hello, Ive a question but not too sure where to ask, so: how can I display what is printed in the command line inside a gui (kivy in my case ) ?

swift crag
spice pecan
#

you can replace sys.stdout to redirect output

surreal sun
#

or that ^

spice pecan
#

If you don't specify a file argument for print, it reaches for the object currently stored under sys.stdout and calls its write method. You can replace it with your own that will write to a label in your GUI either bypassing stdout or duplicating the output there

#

Or, if it's a one-off operation, you can specify the instance as the file argument

swift crag
spice pecan
# swift crag I understand, I am not familiar with sys, but with your explanation, it will def...

!e ```py
from io import StringIO
import sys

class CachedIO(StringIO):
out = sys.stdout
def write(self, arg):
self.out.write(arg)
super().write(arg)

text = StringIO()
print("I'm printed to console!")
print("And I'm saved internally", file=text)
print(text.getvalue()[2]) # Accessing the stored values
text = CachedIO()
sys.stdout = text
print("I'm stored AND redirected implicitly")
print(text.getvalue())

fallen slateBOT
#

@spice pecan :white_check_mark: Your eval job has completed with return code 0.

001 | I'm printed to console!
002 | d
003 | I'm stored AND redirected implicitly
004 | I'm stored AND redirected implicitly
spice pecan
#

You can make your own, which would write the text to your GUI

#

Of course, that's based on the assumption that the output comes from your program. If you're calling a subprocess, you'd need to pipe things differently

swift crag
spice pecan
#

I found out about the io module recently

#

Well, not that recently at this point, about a year ago actually. But it was a gamechanger

lusty scroll
#

it's like tee(1)

spice pecan
#

I really appreciate the unified interface print brings, as well as the fact that it's not tied specifically to stdout and instead actually looks up sys.stdout

lusty scroll
#

even more awesome would be if it were also a contextmanager

#
with CachedIO() as text:
    print("hello")
    output = text.getvalue()
``` or something?
spice pecan
#

!e ```py
from io import StringIO
from contextlib import contextmanager

@contextmanager
def redirect_output(to):
import sys
saved, sys.stdout = sys.stdout, to
yield to
sys.stdout = saved

with redirect_output(to=StringIO()) as cache:
print('Yo')
print(cache.getvalue() * 10)

fallen slateBOT
#

@spice pecan :white_check_mark: Your eval job has completed with return code 0.

001 | Yo
002 | Yo
003 | Yo
004 | Yo
005 | Yo
006 | Yo
007 | Yo
008 | Yo
009 | Yo
010 | Yo
spice pecan
#

With some slight tweaks you can specify whether you want to redirect stdin, stdout or stderr as an optional argument

spice pecan
lusty scroll
spice pecan
#

Yep, that's the intended beauty of it

#

The actual redirection target is whatever you choose it to be

lusty scroll
#

i do like these io interfaces, they're nicely designed

#

I guess a subprocess could be told to use sys.stdout and then it too would be captured

spice pecan
#
@contextlib.contextmanager
def redirect(to, stream='stdout'):
    import sys
    assert stream in ('stdout', 'stdin', 'stderr')

    opened = False
    if isinstance(to, str):
        opened = True
        to = open(to, mode='r+')

    stored = getattr(sys, stream)
    setattr(sys, stream, to)

    try:
        yield to
    finally:
        setattr(sys, stream, stored)
        if opened:
            to.close()
#

Unified version šŸ‘Œ

lusty scroll
#

ahh perfect 🄳

#

what does the yield to do, returm the stream you passed in? so you can do getvalue etc

spice pecan
#

Yeah, so you can do redirect(StringIO()) as cache and get the newly created object

#

(I'm just going to ignore the fact that contextlib.redirect_stdout and contextlib.redirect_stdin exist, shush)

#

yield on its own is part of the contextmanager decorator's protocol, yielding a value is the equivalent of returning it from __enter__, and the rest of the function body is the equivalent of __exit__

surreal sun
#

Agh, I'm kind of confused regarding import hooks, I tested out a Stack Overflow answer on my end but I'm not getting any results

#

but nothing happens whenever I import the file name the import hook was created in

elder blade
spice pecan
#

That's going to be our little secret

surreal sun
surreal sun
lusty scroll
#

if you havent imported the thing you're wantimg to transform yet, its not in sys.modules or anythimg, it should be elligible for your hook

#

what mechanism are you using to set up the hook

surreal sun
lusty scroll
#

does data get printed?

surreal sun
#

Nope

#

Only when I import the file I want to import in the file where the import hook is itself

lusty scroll
#

so only when it's already in sys.modules

surreal sun
#

Yep

lusty scroll
#

what if you reimport some other module

#

or do importlib.reload

#

oh, i missed that you're not trying to do this for every module

#

python tries to use the same loader that imported the top level, is why

#
  • pretty sure
surreal sun
#

Ah, so it would only work for how I’m doing it when I import the file that is supposed to be importing the import hook in the file with the import hook itself

lusty scroll
#

well, i think it doesn't matter which file is doing it, as much as if it's a subpackage where the parent package has been loaded

#

by file i mean if we're talking about pkg.a and pkg is in sys.modules, it doesn't matter if theres an import pkg.a in pkg/__init__.py or foo.py

#

you could check by overwriting __spec__.loader maybe with your loader

#

also look at sys.path_importer_cache

surreal sun
#

Is there just a way for a loader that acts like a normal one but will get any files where the file with the import hook is being imported and changes a certain thing

orchid karma
lusty scroll
#

what is an example of an imported file you want your loader to get

stuck valley
#

I'm essentially aiming to rewrite ideas

prime estuary
#

There's a bunch of lists in sys that you add your instance to, and then the import system will check each in order.

prime estuary
stuck valley
#

thanks?

#

and it's run when something is imported, I guess? I've been looking through the import machinery

prime estuary
#

When you try to import, Python goes through the meta path, and calls the methods to see if each finder can handle it.

#

Meta finders allow you to define handling for modules directly by their name, ignoring filenames etc entirely. The path hooks are a subcategory of that, there's a path based meta hook which goes through sys.path and then calls hooks on each matching file it finds. That way it's easier to say implement a different file format without having to redo that logic.

stuck valley
#

Okay

#

Sounds confusing - I'll look over this in more detail soon

prime estuary
#

Either way look in importlib.abc for the classes you need to implement.

stuck valley
#

That's a lot of stuff to implement

#

I'm just trying to get the file and tokenize it

prime estuary
#

A lot is optional for additional features.

stuck valley
#

The goal is to be able to use very unpythonic syntax natively

#

I've done research already, but quite a bit of it is somewhat over my head.

prime estuary
#

Basically there's two classes you need, a finder and a loader. The finder takes a either a full dotted module name or a file path, and returns a module spec containing metadata and a loader if it knows where the module is. Then, the loader takes care of reading the actual code from the file or wherever.

stuck valley
#

I was recommended the ideas module, which uses "import hooks" - which is presumably a function (or something akin to that) that's called on imports. How to implement this, I do not know.

From this, I'll somehow get the source, then tokenize it, or alternatively get the tokenized source.

#

What's a module spec?

prime estuary
stuck valley
#

ModuleSpec(name='sys', loader=<class '_frozen_importlib.BuiltinImporter'>, origin='built-in')
for sys

prime estuary
#

You'll need a finder and a loader, since you want to change execution.

stuck valley
#

Can this be done in one script? I doubt it

prime estuary
#

Yep, as you can see there's one of the loaders, which is used to load modules builtin to the interpreter itself.

#

There's another which loads .pyd files, and a third for .py files.

stuck valley
#

Okay. Does this need to return a module object?

prime estuary
#

The ABCs you inherit have a bunch of default behaviour, so you can hook in at different levels.

stuck valley
#

I mean, what does the loader return?

#

I'm not familiar with abstract base classes, I'm afraid.

#

Shall we take this to a help channel? I feel like it might be spam here.

prime estuary
#

Sure. They're pretty straightforward, they're basically incomplete classes, with methods missing you need to define, but others with default implementations.

stuck valley
#

Okay. I'll register a help channel.

paper echo
#

If it makes you feel better, this stuff is surprisingly complicated and I have tried and failed several times to understand it by reading the documentation

lusty scroll
#

this almost works

#

lmao

#

on my python it prints

find_spec <abc.MyFinder object at 0x7ff7a00e80> sysconfig (None, None) {}
get_filename <abc.MyLoader object at 0x7ff7a00fd0> sysconfig () {}
get_data <abc.MyLoader object at 0x7ff7a00fd0> ('<sysconfig>',) {}
Hello world from transformed sysconfigmodule

followed by an error

#

no clue how to get subpackages to work

#

has anyone else noticed copying these text blocks inserts a garbage character at the end

#

import sysconfigM-bM-^@M-

#

\xe2 \x80 \x8a for what it's worth

#

U+200A 'ā€Š' 0xe2 0x80 0x8a HAIR SPACE

#

how annoying >_<

lusty scroll
#

weird, that worked on my python 3.9

lusty scroll
surreal sun
lusty scroll
#

oh, gotcha

#

i see why mine broke, I didn't treat native extensions specially

mighty shard
#

I was trying to run a sh file on my windows and it shows this error. Is there any way i can make this work on windows ?

ModuleNotFoundError: No module named 'fcntl'
lusty scroll
surreal sun
frosty arch
#

lol sussy baka

#

yeah you can do it for sure

lusty scroll
#

it's hard to debug >_<

#

the best I can suggest is putting a print at the top of find_spec, get_filename, get_data

#

to make sure all of those are called

surreal sun
#

alright, i'll try that

#

yeah it seems like it only runs when i import the file into the file that has the import hooks itself

#

normally i would have
test.py import import_hook.py
however it only runs the import hook when i
import test.py into import_hook.py

lusty scroll
#

can you send me a DM

surreal sun
#

Alright I turned my DMs on again from this server

gaunt pebble
#

need help building a bot/scalper

sand goblet
#

Do you think they would add a keyword argument to str.find/str.rfind to find the nth occurrence?

grave jolt
#

!d str.find

fallen slateBOT
#

str.find(sub[, start[, end]])```
Return the lowest index in the string where substring *sub* is found within the slice `s[start:end]`. Optional arguments *start* and *end* are interpreted as in slice notation. Return `-1` if *sub* is not found.

Note

The [`find()`](https://docs.python.org/3.10/library/stdtypes.html#str.find "str.find") method should be used only if you need to know the position of *sub*. To check if *sub* is a substring or not, use the [`in`](https://docs.python.org/3.10/reference/expressions.html#in) operator:

```py
>>> 'Py' in 'Python'
True
grave jolt
#

ah

#

I guess you could use re.finditer and itertools.islice

pliant tusk
fallen slateBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.

gaunt pebble
#

so many rules for smh annoying

lusty scroll
#

i have a conceptual issue with find and index, speaking of

#

as we know a str is a sequence. and a list is also a sequence. why is it you can find a sub-sequence of characters, but not a sub-sequence of anything else

spice pecan
#

I'm assuming that's because lists are generally treated as a collection of self-sufficient elements, while strings put a lot more emphasis on the characters being a coherent text

#

Indexing a sub-sequence in a list is a less common operation than indexing a substring

paper echo
#

many (most?) other programming languages have distinct "character" and "string" types, the latter being some kind of sequence of the former

#

i kind of wish python did too, but it would break way too much backward compatibility to make that change now

#

unless they added some kind of type coercion behavior for comparisons, additions, etc

spice pecan
#

I think I like python's approach better tbh

#

The fact that all string operations are available on single characters as well as vice-versa is extremely convenient

paper echo
#
(coerce "hello" 'list)
; (#\h #\e #\l #\l #\o)

(coerce "šŸ¦‡ā†’ė°•ģ„" 'list)
; (#\U1F987 #\RIGHTWARDS_ARROW #\HANGUL_SYLLABLE_BAG #\HANGUL_SYLLABLE_JWI)
#

and the real kicker

(coerce "é" 'list)
; (#\e #\COMBINING_ACUTE_ACCENT)

(coerce "Ć©" 'list)
; (#\LATIN_SMALL_LETTER_E_WITH_ACUTE)
flat gazelle
#

I would argue that the different unicode forms of identical text are an argument for using just strings

paper echo
#

eh, it's the same problems but now hidden

#

you still need something like str.graphemes() for proper text comparison

#

or unicodedata.normalize

lunar heron
#

yeah

flat gazelle
#

yeah, maybe attempting to pave over unicode is just a bad idea

paper echo
#

but i agree that you'd need to have a lot of conversion rules, like + should work on characters and strings interchangeably

flat gazelle
#

at the same time, how often do you actually need to operate on a single unicode scalar value and can't just use the languages number type

paper echo
#

str() of a character should be a length-1 string, etc.

peak spoke
#

I really like how convenient python's strings are in most common use cases

surreal sun
#

Pythons string handling is really nice

lunar heron
#

am advanced

paper echo
surreal sun
#

After using Rust, I am grateful for how nice Python is to us

spice pecan
#

I guess I just like the idea of characters being 1-len strings more on an intuitive level

flat gazelle
#

rust string handling is very correct, but it does have its inconveniences

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied mute to @livid whale until <t:1633032218:f> (9 minutes and 59 seconds) (reason: mentions rule: sent 84 mentions in 10s).

flat gazelle
#

I think I like that python has random string access, even if it does mean 4 byte characters

spark parcel
#

Spam pings?

paper echo
#

two missing features in the python stdlib string handling:

  • unicode character classes in the regex engine
  • ability to iterate over extended graphemes
jovial flame
#

Ghost ping? lol

sour thistle
#

šŸ¤·ā€ā™‚ļø

edgy tinsel
#

whaT's ghost pingh?

sour thistle
edgy tinsel
paper echo
#

and yes i greatly appreciate array-like string lookups

peak spoke
paper echo
#

what does rust do?

lunar heron
#

guys

flat gazelle
#

utf8 strings with all the flaws that has

paper echo
#

do strings have an explicit encoding or something?

naive saddle
edgy tinsel
#

Anyways as I was saying. many (most?) other programming languages have distinct "character" and "string" types, the latter being some kind of sequence of the former
i kind of wish python did too, but it would break way too much backward compatibility to make that change now
unless they added some kind of type coercion behavior for comparisons, additions, etc

lunar heron
#

guys

lunar heron
#

guys

edgy tinsel
spark parcel
flat gazelle
#

anyway, please keep this channel on topic and free of noise, despite the ping spam

paper echo
edgy tinsel
flat gazelle
#

it is 100% correct and forces you to deal with all the complexities that come from using unicode and utf8

elder blade
flat gazelle
#

(except locale aware to lower)

paper echo
#

python has all the unicode complexities too fwiw

#

or most of them at least

flat gazelle
#

yeah, I misspoke there

edgy tinsel
flat gazelle
#

the issue is that most older languages such as java, C# and even C don't have a useful character type

flat gazelle
#

since it was designed for 2 byte codepoints which was assumed to be large enough for all characters, but unicode needs more

elder blade
paper echo
#

utf-32 strings, but encoding/decoding by default to/from utf-8, is probably the most "practical" option

elder blade
elder blade
edgy tinsel
flat gazelle
#

@elder bladeyou can represent all characters in all unicode encodings, but only in utf32 can you find the nth character by index rather than by scanning from start to end

peak spoke
#

utf encodings cover all of unicode, but multi byte chars require more handling

elder blade
flat gazelle
#

@edgy tinsel@lunar heronif you are going to contribute nothing to the discussion, please don't just create extra noise

elder blade
#

I don't think you meant to paste that

lunar heron
edgy tinsel
#

hahaha

#

wrong link

paper echo
#

no i think they did

elder blade
#

lol

flat gazelle
#

!mute @edgy tinsel 1d I already told you not to bring random noise

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied mute to @edgy tinsel until <t:1633118423:f> (23 hours and 59 minutes).

flat gazelle
#

but you want a power of two so that it maps into a native type

#

C++ has u32string for this afaik

elder blade
#

Why would you ever want to eat the cost of 4 times as large string just to get it to align?

flat gazelle
#

so that you can do

string[10]
``` to get the 10th character without scanning the whole string
paper echo
#

to ensure O(1) access without some other fuckery like having to keep a 2nd parallel array that marks codepoint break points

flat gazelle
#

yes, everything but utf32 is variable length

#

even utf16

elder blade
#

I thought it always was X amount of bits?

peak spoke
#

Yes, it's also one of its strengths as its one byte characters intersect with ascii

flat gazelle
#

well, they encode a sequence of unicode scalar values

elder blade
#

Then it makes more sense to think of utf-8 as compression?

flat gazelle
#

well, to an extent

#

it does pack the scalar values tighter

elder blade
#

Scalar values being the first bits in the character?

#

Or the important bits?

flat gazelle
#

a unicode scalar value is a codepoint that maps to a character, rather than being a surrogate

#

overall, the point is that looping over characters in a string in java, JS and C# is generally the incorrect, even if convenient, operation

elder blade
#

Ah

flat gazelle
#

oh nvm, JS seems to do things correctly

sharp flume
#

thats a first

paper echo
#

some languages go even further and strings are sequences of grapheme clusters

#

i think swift is the only one that does it by default though

hexed spire
peak spoke
#

How are combining chars handled for indexing?

flat gazelle
#

generally just separate character

#

in the end, accessing separate characters has multiple possible definitions

paper echo
#

and why some people think it should be either sequences of graphemes or sequences of raw bytes, with codepoints being the worst of both worlds

#

i don't know if i agree, but it's an interesting opinion

peak spoke
#

Yeah I'm mostly wondering about python when like in your example it regards Ć© as a single indexable char even when it's a combined accent and a plain e

flat gazelle
#

the nuclear option is just not having iterable strings and forcing people to be explicit

paper echo
elder blade
#

Hmm...

#

Wat

peak spoke
#

oh right so it doesn't

In [16]: unicodedata.normalize("NFC", "Ć©")[0]
Out[16]: 'Ć©'

In [17]: unicodedata.normalize("NFD", "Ć©")[0]
Out[17]: 'e'
paper echo
#
s1 = ''.join(map(chr, [101, 769]))
s2 = ''.join(map(chr, [233]))

list(map(ord, unicodedata.normalize('NFD', s1)))
# [101, 769]
list(map(ord, unicodedata.normalize('NFD', s2)))
# [101, 769]

list(map(ord, unicodedata.normalize('NFC', s1)))
# [233]
list(map(ord, unicodedata.normalize('NFC', s2)))
# [233]
peak spoke
#

would the only choice here if you wanted to get the whole Ć© be to look around for a combining char?

flat gazelle
#

that's the grapheme cluster

paper echo
#
GitHub

Unicode Standard tokenization routines and orthography profile segmentation - GitHub - cldf/segments: Unicode Standard tokenization routines and orthography profile segmentation

GitHub

A python package for grapheme aware string handling - GitHub - alvinlindstam/grapheme: A python package for grapheme aware string handling

#

this is pretty neat, not sure it's useful for anything

% pipx install segments
  installed package segments 2.2.0, Python 3.9.7
  These apps are now globally available
    - segments
done! ✨ 🌟 ✨

% segments profile <<< "aäaaöaaüaa"
Grapheme    frequency    mapping
a    7    a
Ƥ    1    Ƥ
ƶ    1    ƶ
ü    1    ü
lunar heron
#

yes

grave dove
#

huh so i just discovered that it seems c-implemented modules take precedence and don't give circular dependency errors when naming the file the same as the imported module, but can't find information on why that is whonk

#

for example:

# threading.py, python3 threading.py
import threading # circular dependency error
# _thread.py, python3 _thread.py
import _thread # works fine
#

tested both on WSL ubuntu and windows, odd

#

wonder if anyone else knows this obscurity

prime estuary
#

That'll be because of the order in which the different importer finders are checked.

#

!e

import sys
print('Meta:', sys.meta_path)
print('Path:', sys.path_hooks)
fallen slateBOT
#

@prime estuary :white_check_mark: Your eval job has completed with return code 0.

001 | Meta: [<class '_frozen_importlib.BuiltinImporter'>, <class '_frozen_importlib.FrozenImporter'>, <class '_frozen_importlib_external.PathFinder'>]
002 | Path: [<class 'zipimport.zipimporter'>, <function FileFinder.path_hook.<locals>.path_hook_for_FileFinder at 0x7f323789aca0>]
prime estuary
#

To import, each of the meta importers are checked, builtin (built into the Python executable) and frozen (importlib) come before the file-path finder so they always run first.

scenic atlas
#

hi guys

prime estuary
#

Hello, what's your conundrum?

scenic atlas
#

I created a code that automatically creates a perfect 3d cube in paint, to use it you need to install the pyautogui library (pip install pyautogui) and then just copy and paste!

fallen slateBOT
#

Hey @scenic atlas!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

#

Hey @scenic atlas!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

scenic atlas
#

import pyautogui
from time import sleep

pyautogui.press("win")
pyautogui.write("paint")
sleep(0.5)
pyautogui.press("enter")
sleep(2)
pyautogui.moveTo(x=874, y=381)
def cubo():
pyautogui.drag(0, 250, duration = 0.1)
sleep(0.1)
pyautogui.drag(250, 0, duration = 0.1)
sleep(0.1)
pyautogui.drag(0, -250, duration = 0.1)
sleep(0.1)
pyautogui.drag(-250, 0, duration = 0.1)
sleep(0.1)
pyautogui.moveTo(x=874, y=381)
sleep(0.1)
pyautogui.drag(100, -100, duration = 0.1)
pyautogui.moveTo(x=1124, y=382)
pyautogui.drag(100, -100, duration = 0.1)
pyautogui.moveTo(x=974, y=281)
sleep(0.1)
pyautogui.dragTo(x=1225, y=282, duration = 0.1)
sleep(0.1)
pyautogui.moveTo(x=1125, y=631)
pyautogui.drag(100, -100, duration = 0.1)
pyautogui.moveTo(x=1225, y=530)
sleep(0.1)
pyautogui.dragTo(x=1224, y=283)
sleep(0.1)
pyautogui.moveTo(x=974, y=281)
for i in range(13):
pyautogui.drag(0, 10, duration = 0.1)
pyautogui.move(0, 10, duration = 0.1)
pyautogui.moveTo(x = 874, y = 630)
for c in range(5):
pyautogui.drag(10, -10, duration = 0.1)
pyautogui.move(10, -10, duration = 0.1)
for cont in range(12):
pyautogui.move(10, 0, duration = 0.1)
pyautogui.drag(10, 0, duration = 0.1)
pyautogui.move(6, 0, duration = 0.1)
pyautogui.drag(4, 0, duration = 0.1)
cubo()

#

done!

gleaming rover
#

I must regretfully inform you that you are off topic, and also that you should enclose code in ```

#

anyways...I was thinking about GC

scenic atlas
#

what is Gc?

gleaming rover
#

so the GC is only needed for circular references, right

#

are there any stats on how much memory/etc. would have leaked due to circular references vs non-circular ones?

raven ridge
gleaming rover
#

more like...way back then, was it a big priority? because naively I would think that users wouldn't create that many reference cycles intentionally when writing idiomatic code...?

#

but I have no idea whether that's true or not

raven ridge
#

that's very untrue. reference cycles are extremely common.

#

for example, there's one in:

def foo():
    try:
        1/0
    except Exception as exc:
        return exc
#

because the exception holds a reference to the frame it was raised from, and the frame holds a reference to the local variables of that stack frame, one of which is the exception.

gleaming rover
raven ridge
#

Well, it's definitely true for Python - I'm not sure I can speak authoritatively about how common it is in other languages.

#

that talks about some common ways for reference cycles to occur in Python

gleaming rover
#

but thanks for the link! will look into the issue further

raven ridge
#

most languages that have garbage collection are very dynamic

#

or at least, many are šŸ™‚

sacred yew
#

java

#

haskell

static bluff
#

Can I get you guy's opinion on this?

#

I'm getting really, really close to a basic working prototype

#

I figured I'd sorta sketch out how I want starting up one's own application to look like

gleaming rover
#

you can do a lot of things through reflection

thorny hazel
#
from Application.Application import Application
from Template.Template import Template
from Window.Window import Window

that's beginning to look like Java

#

not to mention all the capitalized module names

fallen moon
#

eivl 19 hours on pycharm bruh you just leave it on or something??

elder blade
#

Take it to Off-Topic

still torrent
#

Is it possible to call VB6 function from python program?

verbal escarp
#

that's the simplest way i think

#

integrating code from other languages can be quite challenging otherwise

still torrent
verbal escarp
#

oha

#

well, then you need to find a suitable match in python

still torrent
# verbal escarp oha

def connectMain():

AppPath = INI_IO("GLOBAL", "AppPath", App.Path, True)
if AppPath == "":
    AppPath=""

JobTyp = [Command if Command.isnumeric() else 0]
AktDate = Now

server = ''
Driver = ''
Database = ''
uid= ''
pwd = ''
connection = pyodbc.connect("Driver={   };"
                            "Server = ;"
                            "Database = ;"
                            "uid = ;"
                            "pwd = ;")

print("S", "Start", "JobTyp = " + JobTyp)
#

In above INIO_IO is the function i am trying to call

verbal escarp
#

what does it do?

still torrent
#

not really sure..dont have access to that till now

verbal escarp
#

i thought it was built in?

still torrent
#

i mean i have been provided this whole VB6 code to convert

#

But it doesnt include that function part

#

i was thinking if there is anything just like we make python usable in shell script

verbal escarp
#

maybe try to run the script in a debugger and see where it leads you

still torrent
#

Sure man will try

verbal escarp
#

on the other hand, maybe you can deduce what the function is supposed to do and then simply take a guess - shouldn't be hard with a variable name as "AppPath" and a check against "" below

#

but then again, i really don't get what if AppPath == "": AppPath="" is supposed to do..

still torrent
#

Thats right..i can simply try it dummy data but the question is whether il be able to call VB function from somewhere else

#

Anyway il try it out

#

Thanks for the help man and please let me know if you come across any library or something that does that

lusty scroll
#

i assume you know about configparser.ConfigParser ?

#

INI_IO seems like it's for parsing an ini file from some quick searching around

still torrent
#

Seems like you are right...i did find one ini file in vb

#

il do some search around about configparser.ConfigParser you mentioned

#

This was helpful

regal chasm
#

if i go from windows 7 to 10 will I lose my files?

grand shore
#

Go to offtopic channels

#

!ot

fallen slateBOT
regal chasm
#

oh didnt know ot means of topic

grand shore
marble nimbus
#

can anyone help me implement my sins in python? i'm looking for a functionality where subclasses can be instantiated directly, but the parent class which would otherwise be abstract can find & "change types" if called with a magic _type_ parameter:

import sys
from typing import Any, ClassVar, Optional, Union

import attr

class DynBase:
  def __new__(cls, *args: Any, **kwargs: Any):
    print(f"dynbase new (cls = {cls})")
    if cls is DynBase:
      # DynBase used directly; find real type from `_type_`
      _type_: Optional[str] = kwargs.pop("_type_", None)
      if isinstance(_type_, str):
        target = getattr(sys.modules[__name__], _type_) # resolve str to class
      else:
        raise TypeError("can't instantiate a `DynBase` without `_type_` kwarg")
      x = target(*args, **kwargs)
      return x
    else:
      # a (real) subclass is being instantiated; continue up __new__ mro
      s = super()
      if s.__new__ is object.__new__:
        x = s.__new__(cls)
        return x
      else:
        # ??
        x = s.__new__(cls, *args, **kwargs)
        return x
  
  def __init__(self):
    print("dyn base init")
    pass
  
  is_dyn: ClassVar[bool] = True

@attr.s(auto_attribs=True, slots=True)
class DynA(DynBase):

  arg0: int
  arg1_a: bool

  def __new__(cls, *args, **kwargs):
    print("dyna new")
    return super().__new__(cls, *args, **kwargs)

@attr.s(auto_attribs=True, slots=True)
class DynB(DynBase):
  arg0: float
  arg1_b: int

if __name__ == "__main__":
  a = DynBase(arg0=5, arg1_a=True, _type_="DynA")
  print(a)

which prints:

dynbase new (cls = <class '__main__.DynBase'>)
dyna new
dynbase new (cls = <class '__main__.DynA'>)
Traceback (most recent call last):
(...)
  a = DynBase(arg0=5, arg1_a=True, _type_="DynA")
TypeError: __init__() got an unexpected keyword argument '_type_'
#

it seems like everything works except that there's the second, automatic __init__ call going to DynA.__init__, and, crucially, the interpreter is passing all the args and kwargs from the original DynBase call, which errors since DynA.__init__ isn't expecting a _type_ arg

#

as far as i can tell, there's no way to prevent the second init except to return an object of the wrong type, and no way to muddle with the args going in like the pop in DynBase.__new__ does. can subclasshook and friends help me here to "fake" it, or am i out of rope to hang myself with?

static bluff
#

I'm trying to keep with the best practice. The capital letter module names are intentional, as is the camel case throughout the library. There's a good reason I swear xD

#

Beyond that, what's good, what's bad?

marble nimbus
# static bluff Beyond that, what's good, what's bad?

didn't ask me, but i'd consider "bubbling up" some of those names to higher import levels or adjusting the names because from X.X import X isn't very pleasant and possibly a source of confusion (don't beginners similarly screw up datetime.datetime)? also not a fan of the the capital module names, but as long as you have a good reason "oh well"

static bluff
#

Yes! I plan on migrating all the publicly facing content of the API to the main module, so that no one will see my horrible uppercase module names

#

I'd like to maybe transition people's comments away from the cases though. Its relatively minor. I'm more concerned with the presentation of the startup procedure, particularly with the use of the dictionaries as arguments

#

Most of the classes one would launch in their opening script take a huge number of arguments—multiple "sets" of arguments in the case of the Application class