« first day (4359 days earlier)      last day (814 days later) » 

04:43
@Aran-Fey if exhausting memory to kill the process is allowed...
>>> safe_eval_norecurse('(lambda a:lambda v:a(a,v))(lambda s,x:["x"] if x==0 else x*s(s,x-1))(100)')
Killed
[5698334.638048] Out of memory: Killed process 1918 (python) total-vm:4071676kB, anon-rss:3905808kB, file-rss:4kB, shmem-rss:0kB, UID:0 pgtables:7704kB oom_score_adj:0
as opposed to a more naive approach which would trigger a MemoryError exception
>>> safe_eval_norecurse("['x'] * 100000000 * 100000000")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 31, in safe_eval_norecurse
  File "<string>", line 1, in <module>
MemoryError
though I guess the idea is to "safely" evaluate some arbitrary statement and fail those that violate the rules, but still can't trust it enough to run in same process space as a server process for example
05:16
Huh. Why doesn't the first one throw a MemoryError?
my hunch is that Python has some heuristics that calculates how much memory it needs in the current operation/frame, but if the values are across frames maybe it can't do that?
I thought throwing an exception is the worst thing you could do, so this is actually really cool
VSR
VSR
05:33
Hi how to add line with width,color,style in excel with win32 python ?
47
Q: Setting styles in Openpyxl

Nelson ShawI need advice on setting styles in Openpyxl. I see that the NumberFormat of a cell can be set, but I also require setting of font colors and attributes (bold etc). There is a style.py class but it seems I can't set the style attribute of a cell, and I don't really want to start tinkering with th...

VSR
VSR
06:28
actually need to add a line shape and set the properties. openpyxl not supported the shapes. i am trying with win32
import win32com.client as client

xl = client.Dispatch("Excel.Application")
xl.Visible = True
wb = xl.Workbooks.Open(file)
ws = wb.Sheets(1)
# xl.ActiveWindow.DisplayGridlines = False
print(ws.Cells(11,2).Left)
ws.Shapes.AddShape(1,ws.Cells(11,2).Left,ws.Cells(11,2).Top,100,100)
ws.Shapes.AddShape(1,ws.Cells(11,7).Left,ws.Cells(11,7).Top,100,100)
line=ws.Shapes.AddLine(ws.Cells(12,3).Left,ws.Cells(12,3).Top,ws.Cells(12,9).Left,ws.Cells(12,9).Top)
line.width=10
line width decrease the line length but i need thickness how to set?
 
1 hour later…
Anonymous
07:45
Okay, so how would you guys deal with having to update a html report in realtime in jinja/beautifulsoup and not save the whole report at the end of all test?
@Warcaith have a template, update data there
Anonymous
Yes, but I'll have to rewrite the whole html file then, isn't that expensive, performance wise?
Anonymous
Rewrite everytime you have some new data
Anonymous
I'm actually using jinja as a templating engine for this, but don't want to make it slow.
Without any context, this sounds like a javascript question. Realtime updates in HTML? That's javascript
07:53
@metatoaster I noticed the same thing too on ipython if you just store a large integer, say, 9999 ** 999999 or multiply and add together multiple large integer. It only throw a memory error when I try to forcefully stop the process
Anonymous
Yeah, it would for sure work in Javascript, but it would be great to do it from Python directly in some way.
To clarify, you're writing your own testing framework, and this framework generates a HTML report, and... what do jinja, soup, and realtime updates have to do with it?
Anonymous
The testing framework is responsible for creating a final report, and we have a requirement that this report needs to be updated everytime something is logged from the framework (e.g., test result, log message, images etc.), with the reason that we can't let anyone be able to run tests and do, for example, a sys.exit() at the end to skip the report from being generated.
Anonymous
That's where the requirement comes from.
Anonymous
Jinja and soup is just tools I'm using to get this working :)
08:00
That sounds a bit like an XY problem. Wouldn't it be better to just catch the sys.exit?
Generally speaking, refreshing/updating the website after every single test is gonna be a massive waste of resources; who needs 100+ updates per second? You'd have to have some really slow tests in order for that to make sense
Assuming you still want to do it, are we talking about refreshing a webpage while it's opened in the browser, or just re-creating a HTML file?
If you worry about malicious actors using sys.exit, then you've already lost. Alternatives such as os._exit will kill the process clean.
Anonymous
Well, yeah, we want to prevent everything, so that's something we will do also. Trust me, I've talked with them about this requirement too, but yeah, it's important to get it right. It's hard to catch all edge cases though, which is why we want to update this static HTML file in realtime too.
You could run the tests as subprocesses with unbuffered I/O, but that brings its own problems.
Anonymous
@MisterMiyagi We are wrapping Python in a C++ application that is responsible for handling the test evidence (reports etc.), but can't really force the Python users to NOT do a sys.exit(). However, we want to ALWAYS have the results until something like that happens.
Anonymous
sys.exit() is dumb, no one will do it, but you get what I mean.
08:06
Well... no, actually I don't.
Anonymous
@Aran-Fey Just re-creating a HTML file.
Anonymous
@MisterMiyagi Okay, but the requirements are as they are and it's necessary to do it in this way, as we do not want to lose any evidence, ever.
Well, you cannot achieve that. So investigating what exactly are the constraints of the requirements seems prudent.
Anonymous
We have achieved it in C++ (but not 100% waterproof, of course), but the HTML generation there is pretty messy, which is why I want to make it better in our new Python API/framework.
Rewriting a HTML file is, by design, a fairly inefficient operation. If you change something in the middle of the file, you have to rewrite half of the file. The only thing you can optimize is caching (parts of) the generated HTML so you don't have to re-create it every time. (Basically, keep the 2nd half of the HTML in memory as a string and just write that to the file once you've made your changes in the middle.)
08:11
@MisterMiyagi The actors aren't malicious. But they might make dumb mistakes.
@PM2Ring I've used os._exit on purpose, so even assuming no malice that's a real thing that could be in the code and run by accident.
Fair point.
I get the impression that Warcaith isn't running code written by untrusted outsiders. It's code that comes from within his organisation. Of course, it's not always easy to tell the difference between malcious code & honest mistakes. ;)
Anonymous
Sounds like what I was thinking of doing, which is generating output of each test case in separate html files and have references to these files in the final report.html. A simple JS file could then be used in the final report that extracts data from these "cached" files and make them appear in the report everytime you open it.

Thanks for the help, I'll try some different things with caching the output and see what I can do with it. :P
Anonymous
@PM2Ring Haha yeah, it's totally within my organisation, but the framework is going to be used by different teams all over the world when developing games, which is why we want to have a solid "evidence generating" system. We are already using other tools for emitting other type of data in realtime, the report is just a way of letting the developer/project lead see the final results in a more convenient way.
08:54
@Warcaith if you want to do that, there is a couple existing ways using Flask, eg: stackoverflow.com/questions/61398680/…
Anonymous
@NordineLotfi Thanks, going to take a look! :)
if you were to use websockets only, you can also do it :) just use something like tornado and some simple JS to do the same thing
I did that once, let me find an example somewhere
ah, found what I used once: github.com/albertobeta/UberSimpleWebsockets shows a nice working example using websockets
Anonymous
Thanks, I'll check that out! :)
Anonymous
@NordineLotfi Doesn't this have the same problem though, if I want to save the HTML report everytime new data is appended to it?
@Warcaith hmm, I only thought of the first requirements mentioned previously here
@Warcaith so essentially, you just want the report to be generated, at least partially, so even if the user exit, it will still be there? (and maybe either continue generation from there or use that as is?)
Anonymous
09:14
Yes, exactly. It's easy to implement something like this, if you do not care about performance at all (solution=rewrite_everything_everytime). However, I do care about the performance.

We do not have any requirement for "continue generation", but we do want to store everything that happend until "that criticital point". :)
ah, I see what you mean yeah
Anonymous
I'm currently thinking of splitting up the generation into different cached files that the final report can find with help of an included .js file.
Anonymous
final_report.html
cached_section_with_unique_id_1.html
cached_section_with_unique_id_2.html
cached_section_with_unique_id_3.html
cached_section_with_unique_id_4.html
question: why not generate the report in another format that you can much more easily generate in a partial way (eg: markdown, normal text, etc) and then convert that to HTML after it is finished generating?
@Warcaith yeah, doing it in chunks or multiple files and then appending them at the end would work too
Anonymous
That would work of course. The only "problem" is that I'll need to move the resposibility of the HTML generation to another source. It's a good solution though, going to take that with me and talk with my team. :)
Anonymous
09:21
Btw, remember that I'm not the one coming up with these requirements... :D
@Warcaith don't worry, I saw that you mentioned that last time too (and it's also easy to guess that based on the context too)
btw, since you mentioned using jinja already, found this: stackoverflow.com/a/68659995/12349101
Anonymous
Oh, that seems really interesting!
Anonymous
Thanks for looking into this, I really appreciate it! :)
No worries :D
 
3 hours later…
12:28
morning cabbages, folks
Greetings
It's been a while. Potato?
I'm continuing to solve problems that have no apparent practical applications
I started today with a sort of modular arithmetic system and I think I'm about to reinvent dot products
that sounds like fun :)
I started with "There is some function f such that f(f(f(f(x)))) = x for any x" and then I defined g(x) = f(f(f(x))) and then I proved that g(g(g(g(x)))) = x and then...
12:39
I'm getting flashbacks from CSC206 from like 14 years ago. Fun times
13:38
Does anyone have experience with connecting to a remote DB through a VPN? This came up as the first result for my search despite not mentioning a VPN at all. Are they related things?
@roganjosh They're similar ways of tunneling through to a different network. But I think "connecting via ssh" is typically not something people regard as a "VPN"
Put differently, is something named SSHTunnelForwarder likely to be related at all to the concept? I don't know anything about them on a technical level but I do know that I connect to the work VPN with TunnelBlick so there's at least a word in common :D
usually when you mention "VPN" you tunnel a whole network or a couple of hosts through. And you do it both ways. Whereas with SSH you usually just tunnel one host and a single TCP (or UDP) port.
Hmm, ok, that makes sense to me, thanks. I wonder whether our customer misspoke (I wasn't in the call but this got forwarded to me)
Trying to think it through, though, the VPN must have a concept of locality within its own network, so if they're both related to SSH then the same technology could be used to simply bypass the network routing but get straight to a single server on that network? The act of typing that out also did a lot to completely overrule my own thinking by the time I got to the end...
FWIW, we use sshuttle for ad-hoc and temporary forwarding. It is adequately described to "works as a poor man's VPN."
13:49
@Kevin If f(f(f(f(x)))) = x is true, does it mean that applying f four times on x would equal x, or f is an Identity function?
f = lambda x: x is one possible definition of f, sure. But there are other possibilities, such as f = lambda x: x*complex(0,1). (Assuming x is a number)
>>> f = lambda x: x*complex(0,1)
>>> f(23) == 23
False
>>> f(f(23)) == 23
False
>>> f(f(f(23))) == 23
False
>>> f(f(f(f(23)))) == 23
True
I mentioned modular arithmetic earlier. You can define f = lambda x: (x+1)%4, and f(f(f(f(x)))) will equal x, as long as x is in {0,1,2,3}
@Kevin Niceeeee :-)
14:34
df.groupby('a').agg(lambda x: list(x)) groups by the column a and produces a list of all other columns in pandas -- is there a way to produce a list of only a particular set of columns?
no i actually mean, produce a list of only a particular set of columns but no list for other columns
the other columns would contain identical data if made into a list
I still think filter would be useful
okay thanks will check figure out then
15:08
Cbg Kevin
hello, guys
when I use Flask locally in my project I have to import local files like:
import constants
but once in server I have to change it to:
`from . import constant`
is there anyway to make it works in both places at the same time?
When you run it locally, how do you do that? Through your IDE? Command line?
Out of curiosity are you running different versions of python between the two? Specifically, 3.7 on one machine and 3.8 on another?
I'm not too hot on the import machinery but recently I've found my typical flask structure seems to throw errors when moving from 3.7 to 3.8. Maybe I'm doing false attribution, though
15:24
@Aran-Fey command line
@roganjosh 3.10.6 in my local macOS machine and 3.8.10 in my Ubuntu server
Like python project_dir/foo.py? Try python -m project_dir instead (will need a __main__.py for that though)
(And use the from . import constant style imports)
let me check
Did you containerize your app?
This is the moment where I realize that I'm out of my depth and web dev is (yet still) crazier than I thought
I should add that I'm using pipenv
so I cannot do python -m outside from my project directory
I only use pipenv in my local machine
15:29
I don't know what pipenv is, so I shall admit defeat at this point
thank you anyway
@0x263A just seen this. No, I didn't
any chance you can create a MRE demo project? Also, are you able to check what gets put in sys.path in both conditions
I found something interesting in Stack Overflow
let me try, I'll let you know
16:05
@PeterT anything that gives access to a network can technically become a VPN, or at least a "proxy". At the end of the day, it kind of depends on what can be defined here, since there is an instance of proxy being encrypted like a VPN, and VPN that do not encrypt their packet (eg: there is an option to disable some of the encryption from OpenVPN, etc)
@PeterT you can have a VPN setup with only client + server on two sides, so not necessarily (always) "both ways" :)
@MisterMiyagi nice that you mentioned sshuttle. Used it myself but while it does work sometimes, there a couple of tiny problems that make it not always work (eg: if you want to share internet connection through ssh, it doesn't always work on linux, etc). There a couple of unresolved and related issues on their github
but when it comes to ssh tunneling, the simpler way is just:
ssh -f user@yourremoteorlocalip -i ~/.ssh/yourprivatekeyhere -L 5900:localhost:5901 -N
@roganjosh the above is just an example for vnc I did once. just make sure the port aren't already used on either end, and it should work, might help
@DanielGarcíaBaena think this is related to this issue on their github: github.com/pypa/pipenv/issues/4555
16:25
@NordineLotfi thanks!
@NordineLotfi Thanks. I wonder how one would make use of this in our setup. I don't have a lot of flexibility in our system but the easiest thing to imagine would be a cron job that spins up a Docker container that then runs a shell/python script. In that case, could I get the shell script to set that parameter and then trigger a python script to run under that VPN "context" (for lack of a better word)
Seems my colleague understands your suggestion much better than me - he's now talking about moving things between supercomputers at uni. Thanks for the lead :)
@DanielGarcíaBaena How are you running it? Through gunicorn?
@roganjosh yes
Ok. I'm guessing the code can't be shared? My website code will run both locally and through gunicorn without changing any imports but I can certainly see how pointing gunicorn at the entrypoint for certain points vs. running from the command line could cause import anomalies
16:41
it is not complicate just a init.py importing a constants.py with a few constants in it
if you run it locally it's OK just with import constants
In which case can you give an MCVE on a gist or something?
but once in server you need to change it to: from . import constants
# __init__.py

import constants

print(constants.GREETING)
# constants.py

GREETINGS = "hi!"
thats only working locally
if you want it to run on server, you need to modify the import to: from . import constants
You're just re-stating things. I'm asking for a complete example that I can actually run. So far there isn't a single line of Flask in there or anything that I could run through gunicorn
I know, sorry
but this code cannot be shared
That's why I said both MCVE and example. You keep saying how simple the code is, so you should be able to make a representative example?
16:55
the one I shared before it's failing the same as with my full code
so far, I assume it should be something related with Gunicorn or Ubuntu
You didn't share any runnable code and I already said it's almost certainly gunicorn
give me one minute
We can actually quickly figure out who's right and who's wrong... if the directory that contains constants.py has an __init__.py, then your server is right
And either way, achieving imports like from . import foo instead of import foo should be your goal anyway
@Aran-Fey then where should constants.py be?
I don't understand that question. As long as it's inside a package, you can put it wherever you want
So judging by the pastebin, you do have an __init__.py?
17:08
it is that pastebin
Alright, then the correct import is from . import constants. So now the question is, how on earth are you running this code that makes import constants work?
How do you start the server locally?
with: pipenv run python3 __init__.py
You're running an __init__.py directly?! Lord help me
Now this is where the web dev part comes and I could be wrong, but it should work if you just move that code into a __main__.py file
And then call pipenv run python3 -m the_folder_that_contains_the_code
17:19
but if you run python3 -m the_folder_that_contains_the_code Pipfile would be outside of the project directory
isn't it?
I don't think so. The project directory isn't the same thing as the directory where your code is
it is not but Pipenv files should be inside of the directory where the code is
Wait, really?
I had a quick look at pipenv and I disagree with pretty much all of its design decisions, so I guess this is plausible
I think pipenv run python3 ../the_folder_that_contains_the_code should also work
I'll try that then
just one quick question
Your code shouldn't be running inside __init__.py
17:27
whats the different about naming your main file __main__.py or __init__.py?
Just one of those options is okay to do
Use the Application Factory pattern
@vaultah even when you try pointing gunicorn to it?
I will check it out
@DanielGarcíaBaena __main__.py is the entry point for execution, __init__.py is the entry point for importing. python -m your_module and python your_module execute __main__.py. import your_module executes __init__.py.
I see
it is possible that GAE does not use any __main__.py file?
17:32
I don't know what GAE is, but that sounds like another thing that belongs in the "stupid, but plausible" category
I stoped using __main__.py because GAE default configuration asks you for an __init__.py instead
is GAE == google app engine?
yes
anyway, thanks for your time
I will check everything out
have a nice day
@DanielGarcíaBaena you can use this project structure too if you want: stackoverflow.com/a/55308619/12349101
cool
thank you @NordineLotfi
17:48
@roganjosh No problem. Btw, don't know if this is for moving just files, or sending tasks to clusters/worker/parallel processing, but if this is done on wires (no wifi/remote connection) you could benefit immensely by playing around with the -o Compression=no flag on ssh, as well as switching cipher algorithm. Many benchmarks show that some of them are faster than others, but I recommend testing them again based on the task at hand.
Continued progress on my code tangler. It takes in operator(self(self)(rest(seq)))(top(seq)) and it returns S(S(K(operator))(S(S(K(self))(K(self)))(S(K(rest))(K(seq)))))(S(K(top))(K(seq)))("nonce"). These expressions behave identically, except the latter waits as long as possible before doing any actual work.
A handy trick for solving my problem from yesterday, which involves code resembling a if b else c except without the short-circuiting. I am making my code lazy, with extreme force
there is also a way to disable encryption entirely on ssh's end, but definitely risky if you're not using ssh offline through direct wiring :serverfault.com/a/606367/576424
18:03
There's absolutely no way I'd be disabling encryption. I just can't quite visualise what this all means for our connector
I don't know either, but thought this might be helpful if the connection is done offline through direct wires
(at least in term of speed if that's needed)
Anonymous
How is this even a valid "error"?

Exptected to return "Optional[ClassA]", got no return
Anonymous
How do I type hint a optional return value then?
Anonymous
:||
Same idea but with `-1`.

>>> def f(x): return x*-1
...
>>>
>>> x = 10
>>> f(f(f(f(x)))) == x
True
>>>
18:10
Yeah. That one has a period of two. By which I mean, f(f(x)) == x
@Warcaith I think it's saying that there's literally no return statement in the function? In which case the annotation should be None
@Warcaith first time in my life I get no result on a python error message o-o
Anonymous
Hmm, but I thought that a "no return" would automatically mean that it return -> None
Anonymous
But that doesn't seem to be the case here
I'm 75% sure it's not a python error message*
18:11
@Kevin Ah, correct.
@Kevin that would explain a lot then
Anonymous
I'm using this type hint: Generator[ClassA, Any, ClassA]
Anonymous
The reason is that I can both yield and return inside it.
Anonymous
But yeah, it expects that I both return and yield now.
Anonymous
Which is why I used "Optional[ClassA]"
Anonymous
18:12
But still got the warning. GAAAH
Anonymous
:'D
Keep in mind that a function considers itself a generator even if there are circumstances where it can execute from beginning to end without ever hitting a yield.
Anonymous
Really? When I don't yield, I get back "NoneType" and not a generator.
>>> def f(x):
...     if x == 0:
...         yield 1
...         yield 2
...         yield 3
...         return 4
...     else:
...         return 5
...
>>> x = f(1)
>>> print(x)
<generator object f at 0x000001DF8FE99A10>
And next(x) crashes with StopIteration: 5, which is what we'd expect a generator to do
Anonymous
Aaah, I see. But if I have an @abstractmethod that people can implement and then do no return, no yield, single return, single yield, multiple return, multiple yield, you have three different return types.
Anonymous
18:16
NoneType, ClassA and Generator
Are you sure you care about the return type of your generator? Most people don't even know how to access that value...
Arguably, it's a violation of liskov's substitution principle for different implementations of a method to vary between 0 yields and 1+ yields
Unless the only thing you guarantee about the method is "when I call it, it returns an object"
That's one heck of a guarantee, wow
Local man solves halting problem -- "simply promise to always halt"
Anonymous
So, what should I do instead if I want the developers to be able to "return multiple items via a generator => yield", "return a single method and STOP => return" and "return nothing => no return, no yield"?
18:20
That's just Any then
FWIW I violate liskov's substitution principle ten times a day. But it's good to be mindful about it.
...more formally, Union[Generator, Any, None]
Anonymous
Aaaah, that's true. But isn't the last statement in Generator[..., ..., this] an actual return type?
Anonymous
Hmm
Anonymous
Generator[YieldType, SendType, ReturnType]
18:22
What's "an actual return type"?
Anonymous
What the heck is ReturnType
Anonymous
If YieldType is the object yielded?
Well, the type of the object that comes after your return? Generator[..., ..., int] would be like return 3 for example
Not a rhetorical question -- if a function returns None, are you expected to annotate it as returning a NoneType? Or can you just say it returns None?
What does that mean? How do you "say" it returns None without annotating it?
18:24
Ah, the docs say "None as a type hint is a special case and is replaced by type(None).". Handy.
Aaaahhh, now I understand the question
Anonymous
Okay, this is how I thought the generator type hint is used:

def function() -> Generator[Optional[ClassA], Any, Optional[ClassA]]

=> This function can yield and return ClassA, but a NoneType is also valid.
Sounds correct to me
Anonymous
PyCharm's warning is maybe not resolving the type hint correctly then :p
Depends on whether "can yield and return ClassA" means "it can yield a ClassA and it can return a ClassA", or "it is capable of yielding, and it can return a ClassA"
Anonymous
18:27
It should be "it is capable of yielding, but also capable of returning, but None is ok too"!
Anonymous
Hahah :'D
Anonymous
This is interesting
Depends on whether "None is ok" means "None is something that can be returned" or "None is something that can be returned, and None is something that can be yielded"
Anonymous
Okay, a return or yield should be able to be completely omitted.
Anonymous
That is what I'm trying to describe with the hint
18:30
I guess PyCharm checks if your annotation matches your code, even if you marked it as an abstractmethod
Depends on whether that means "There may be zero returns. There may be zero yields" or "if there is at least one yield, there may be zero returns. If there is at least one return, there may be zero yields". Compare to: "you can live without your left or right kidney"
Anonymous
def function() -> Generator[Optional[ClassA], Any, Optional[ClassA]]:
yield ClassA()

PyCharm: Expected to return "ClassA", got no return
Note. I am being intentionally difficult, and you may ignore me at any time
Anonymous
No, you don't expect it, you are Optional!
Anonymous
:|
Anonymous
18:33
@Kevin Hmm, you mean that it's maybe hard for PyCharm to get what I really mean? ;p
Pop quiz!
def gen():
    return 'How do you access this?'
    yield
Computers are dumb and we must explain things to them carefully
@Warcaith it's hard but not just because of the requirements. Pycharm has a lot of bugs and non-supported type hinting pitfalls...you can see what I mean if you look around on github or/and SO using search term such as "Pycharm error type hint".
I have the ban hammer ready for anyone who tries to pass off __code__ or dis or ast as a solution btw
My solution, which I think will not get me ban-bonked pastebin.com/raw/up9ABxmg
18:37
ah, I was about to mention ast but then you edited it :P
* Looks around shiftily * Nope, wasn't trying that
@Aran-Fey Honestly, I was considering that :D
@Kevin Bingo!
I've done it like, twice, in actual serious code
@thefourtheye It's not the first time I've posted a riddle in this room, and I know how you people think... :P
Anonymous
18:38
Well, this actually works...

-> Union[Optional[ClassA], Optional[Generator[ClassA, Any, None]]]
Anonymous
But it's so freaking hard to read, lol.
@Warcaith that's usually what happens when you get into type hinting, at least I always find it hard to read...
@Warcaith Should be equivalent to Union[None, ClassA, Generator[ClassA, Any, None]]
Anonymous
That looks better, I guess..? Hmm..
Anonymous
What is the "ReturnType" in the generator actually?
Anonymous
18:40
The third argument.
The type of the value that gets returned, presumably. For example, in Aran-Fey's gen, its return type would be str.
Just to make sure we're all on the same page: a function is allowed to yield a value, and then later return a value.
@Kevin I noticed you consistently use my full name, and I appreciate the attention to detail, but just to let you know, it's also perfectly ok if you just say "Aran"
Heck, I wouldn't be opposed to being "the fairy" either
@Aran-Fey I always did that too since I thought this was preferred by default
Ok. My default algorithm for identifying first names is to split on whitespace, so the hyphen throws everything into disarray.
same here
18:51
To be honest, I do regret picking this name a little bit. Most services don't allow hyphens in names, and some don't even let you use underscores, so it's a bit of a challenge sometimes...
yeah, picking names is hard. I still doubt if the name on my github is a good one, but I don't really know a better one, so yeah
Anonymous
An optional method is just a method that omits the @abstractmethod decorator, right? Like, "override this if you want this functionality".

def function():
    pass
Anonymous
Is there any way for me in the base class to see if a method is overrided?
Yeah, something like if self.function.__func__ is not __class__.function:
Anonymous
Aaah, I'll try that :)
18:55
Or type(self).function is not __class__.function
This doesn't strike me as idiomatic
If the base class defines a function that does nothing, I don't think it's entitled to snoop through its child classes and see if their functions also do nothing
Btw, I don't think there's a name for this kind of method. Calling it "optional" probably doesn't invoke the right idea in most people's heads
This concept is pretty far off the beaten path, so you'll be inventing a lot of your own terminology and rules
Not that there's anything wrong with that. I invent my own terminology ten times a day. You just need to make peace with the possibility of getting stuck, and searching for expert advice, and discovering that there's only one expert in the world, and it's you
Not even DenverCoder9 has set foot on these unmapped lands
basically, you need foresight depending on your requirements. Also some test cases would help, along with a lot of prototyping, etc
Anonymous
Thanks you all for the feedback! :D
Anonymous
19:09
One more, weird question...
Anonymous
It there anyway to wrap a baseclass method around the subclass method with the same name?
Anonymous
Is that even a thing?
Anonymous
Lol
Anonymous
:D
Anonymous
I'm really on an adventure here
19:11
I usually make a public method in the base class and then another private abstractmethod with the same name
class MyAbc(abc.ABC):
    def do_stuff(self):
        self._do_stuff()

    @abc.abstractmethod
    def _do_stuff(self):
        raise NotImplementedError
Anonymous
Yeah, I'm currently doing it this way. It's maybe the better way doing it rather than having decorator magic out of the blue
@NordineLotfi Sorry, got pulled into something. No, no "wires" involved, it's our system trying to reach directly into an alien system, one of hundreds of different customers. I don't care about efficiency at this stage, just actually being able to function
If you want a subclass method to run code from the base class' method, consider super()
It's extremely magic
Anonymous
Yeah, but super doesn't really wrap around the method :p
I think I need to go back to them with questions because this crossover between VPN/SSH is leaving me pretty confused. Hopefully, if they set up the system, they'll be able to tell us what we need to do to get external access to our AWS systems
19:16
@roganjosh I see :) then yeah, keep encryption/everything default then. I just thought that performance would have been wanted (at least additional) so that was just a suggestion
Indeed it does not really wrap around the method. But it may be a building block for achieving that. Or maybe it's shiny enough to convince you to abandon the wrapping-based design in favor of a super-based design.
Sure. Not a bad suggestion and it's appreciated, thank you :)
19:37
@roganjosh yeah, asking them would help especially since I'm unsure myself on how they would want to implement this. I do know that this can be done using either ssh or OpenVPN..it's just that using the latter is horrendous later on because of how tricky it is to write config files for it, and the former is easy, but I guess it might not scale the way they'd want, unless it's done in a certain way, whatever that is.
I remember a family member working at a remote company once, and everyone there, customer support, IT, etc were all using OpenVPN for most of their works. This was also to "make sure" everyone was working and tuning in, but this was also used as a "security" measure to use their network, tools, etc
It depends what they want us to SSH into. I fear that we would need some code living on the client side to pull the data and push to us. If we have nothing living on their side, I'm utterly confused about how we make a pull API on the server side
yep, that's true
I think I need to do some more research anyway, I'm just reacting to "VPN" being mentioned in a conversation about ingest with little context and it's spooked me
if it's done using keys, certificate, etc then there would also be a couple of other "files" on client side (and also server side but that's not a problem on that side). It's really tricky yeah
Anonymous
20:11
Best way to document which exception can be raised by a method?
That goes inside the docstring, with whatever docstring format you prefer
Sphinx uses something like :raises ValueError: if the message_body exceeds 160 characters per default, for example
Anonymous
Alright, thanks :)
Anonymous
Alright, I've got something working now.
Anonymous
I can both yield and return "ClassA" now.
Anonymous
I do some processing on all yielded values, but I want to do exactly the same process on the StopIteration (return value).
Anonymous
20:24
Best is to create a method that is used both in the generator "for loop" but also in the except StopIteration, right?
Yeah, that sounds good
Anonymous
Is it fine to have this method inside the same method?

def function():
    def _inner()
        pass

    try:
        for value in generator:
            _inner(value )
    except StopIteration as e:
        _inner(e)
Anonymous
Or should you avoid this?
I think it's fine
I'm curious about why you think this is fine?
I can't understand a scenario in which this would a) be needed or b) is clear for other people
20:33
If I say it's not fine, it should be a staticmethod, someone's gonna come along and yell "staticmethods are evil, just make it global". So then you make it global, and suddenly it's 50 lines away from the only place where it's ever called and you have 0 context
There are numerous times where you guys hack the data model a lot, and I do enjoy those demonstrations. Equally, I just don't find this kind of code in the wild. I'll happily sit down and shut up if you can point me to a mainstream library using nested functions like this
I am aware that I'm in the minority with this opinion
Probably should've said that right at the beginning. Oh well
Even putting that aside, is this kind of stuff used in mainstream libraries? I still need to know whether I'm on the wrong side of the debate.
I reiterate that I find it really quite cool how you can manipulate the data model, but I don't think this kind of stuff actually goes into production?
Doing crazy things with python internals and using a nested function are two different pairs of shoes, no?
Note: I'm not gonna take a fringe argument here. I want a big-hitter library to disprove me :P
20:38
Yeah, sorry, I don't know one :D
I know quite a few libraries that write code in __init__.py files though...
Sure, Flask's application factory does that from my link earlier. I'm talking about the current question about nested functions
Just wanted to point out that big libraries don't do everything right...
I can certainly agree on that
Meanwhile, over a couple of weeks, I feel that @Warcaith might be over-engineering
Oh, I've been in that boat! The breakfast toast they serve there is amazing, but you have to arrive 20 minutes early to put the bread in the Rube Goldberg machine
Anonymous
21:02
@roganjosh I didn't use the nested methods at the end, as I realised it was unnessary. I also do think that it's kind of ugly doing it, so I'll probably keep trying to avoid them.
Anonymous
@roganjosh I'm also trying to avoid to over-engineer things, which is one of the reasons I ask stupid and weird questions here all the time. Feeback from you all is great! :)
Anonymous
@roganjosh We have some really annoying requirements though, so some things will sound like over-engineering, when the reality is actually different.
Anonymous
But I really appreciate if you tell me when you think I'm doing something weird, because I love that kind of feedback! :D
Anonymous
21:46
Is there anyway to import the whole package inside a submodule?
Anonymous
Like...
Anonymous
import package as pkg
Anonymous
Instead of importing each module separately?
Anonymous
I get the classic "partially initialized module 'package' has no attribute 'ClassA'"
Anonymous
Or can I only do that outside of the package?
Anonymous
21:49
I'm importing all classes and functions with "from .module import ClassA, function_a, function_b" inside the init.py file.
Anonymous
But if I import the whole package inside for example another module, I get the error above.
Anonymous
I'm really trying to figure out this circular import thingy
Anonymous
22:01
Ignore what I wrote, I fixed it :p

« first day (4359 days earlier)      last day (814 days later) »