question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

six: burn the bridges

See original GitHub issue

Let’s try and automatically un-six python source. Here’s a quick audit of what six does and how to undo it in python 3:

From the docs:

trivial replacements

  • six.text_type => str
  • six.binary_type => bytes
  • six.class_types => (type,)
  • six.string_types => (str,)
  • six.integer_types => (int,)
  • six.unichr => chr
  • six.iterbytes => iter
  • six.print_(...) => print(...)
  • six.exec_(c, g, l) => exec(c, g, l)
  • six.advance_iterator(it) => next(it)
  • six.next(it) => next(it)
  • six.callable(x) => callable(x)

trivial removals:

  • python_2_unicode_compatible (remove decorator)

    @six.python_2_unicode_compatible
    class C: pass
    

requires parsing a function call

  • six.u('foo') => 'foo'
  • six.byte2int(bs) => bs[0]
  • six.indexbytes(bs, i) => bs[i]
  • six.iteritems(dct) => dct.items() # also {iter,view}{items,keys,values}
  • six.create_unbound_method(fn, cls) => fn
  • six.get_unbound_method(meth) => meth
  • six.get_method_function(meth) => meth.__func__
  • six.get_method_self(meth) => meth.__self__
  • six.get_function_closure(fn) => fn.__closure__
  • six.get_function_code(fn) => fn.__code__
  • six.get_function_defaults(fn) => fn.__defaults__
  • six.get_function_globals(fn) => fn.__globals__
  • six.assertCountEqual(self, arg1, arg2) => self.assertCountEqual(arg1, arg2)
  • six.assertRaisesRegex(self, fn, *a, **k) => self.assertRaisesRegex(fn, *a, **k)
  • six.assertRegex(self, *a) => self.assertRegex(*a)

maybe replace with literal?

  • six.b => replace with bytes literal?

need to know that you’re not in a place where a raise statement is invalid

  • six.raise_from(exc, exc_from) => raise exc from exc_from
  • six.reraise(tp, exc, tb) => raise exc.with_traceback(tb)

probably can reuse the “new style class” logic

  • class C(six.Iterator): => class C:

requires multiple function call parses, probably hard

  • class C(six.with_metaclass(Meta, Base)): => class C(Base, metaclass=Meta):

  • (rewriting add_metaclass)

    @six.add_metaclass(mcs)
    class C(...): pass
    

    to

    class C(..., metaclass=mcs): pass
    

probably can’t do (requires introducing an import)

Note that for six.moves I’m planning on handling that in reorder-python-imports

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, May 22, 2019

with #149 I think I’m finally calling this done!

I’m planning to try and do something clever with version-guarded blocks later

0reactions
hugovkcommented, May 22, 2019

Good work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Six Burning Bridges - song and lyrics by Troubadour Rose
Listen to Six Burning Bridges on Spotify. Troubadour Rose · Song · 2013.
Read more >
Seether - Burn The Bridges (Official Visualizer) - YouTube
Listen to Burn The Bridges from Curiosities, Rarities & Pariahs: found.ee/seether-curiosities-rFollow us: https://found.ee/SeetherWebsite ...
Read more >
Project Eighty Six - Songs To Burn Your Bridges By - Discogs
Project Eighty Six* – Songs To Burn Your Bridges By ; The Great Golden Gate Disaster, 3:42 ; Say Goodnight To The Bad...
Read more >
6 Cases When You Should Burn a Bridge or Two | Inc.com
People who constantly burn bridges over time rather than building on existing relationships find their way in life ever more difficult. Still, ...
Read more >
Bridge Burning and the six other ways to quit your job - Big Think
Bridge Burning and the six other ways to quit your job ... Klotz and Bolino found that people who burned bridges or impulsively...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found