Skip to content

Instantly share code, notes, and snippets.

@sb2nov
Created June 6, 2017 00:06
Show Gist options
  • Select an option

  • Save sb2nov/52b5091fcc7135bcd02948088d876d5b to your computer and use it in GitHub Desktop.

Select an option

Save sb2nov/52b5091fcc7135bcd02948088d876d5b to your computer and use it in GitHub Desktop.
Test python import
class A(object):
def __init__():
print 'A'
from a import A
class B(A):
def __init__():
print 'B'
from a import A
class C(A):
def __init__():
print 'C'
from a import A
print A.__subclasses__()
# []
from b import B
print A.__subclasses__()
# [<class 'b.B'>]
from c import C
print A.__subclasses__()
# [<class 'b.B'>, <class 'c.C'>]
@robertwb

robertwb commented Jun 6, 2017

Copy link
Copy Markdown

If you just write "import b" instead of "from b import B" this will work as well. Likewise, if you import (say) c from b.py, there's no need to import it from test.py.

@robertwb

robertwb commented Jun 6, 2017

Copy link
Copy Markdown

@sb2nov

sb2nov commented Jun 6, 2017

Copy link
Copy Markdown
Author

Thanks @robertwb, one follow up questions for the beam plugin case

myfs.py installed via pip somewhere

class MyFS(FileSystem):
   def __init__():
       print 'This is my fs implementation'

my_pipeline.py

p = Pipeline() | TextIO("myfs://path/to/file")
p.run()

python -m my_pipeline --runner DataflowRunner how does this find the myfs implementation when it is not imported anywhere. Is the hope that the user is going to import this in the pipeline ?

@robertwb

robertwb commented Jun 6, 2017

Copy link
Copy Markdown

The user must cause this to be imported to indicate that they want to use it. (Perhaps directly, perhaps some runners will import certain filesystems themselves.)

@sb2nov

sb2nov commented Jun 6, 2017

Copy link
Copy Markdown
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment