Conditions | 11 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like main() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | """CLI for accessing the gtk/tickit UIs implemented by this package.""" |
||
88 | @click.command(context_settings=dict(allow_extra_args=True)) |
||
89 | @click.option('--prog') |
||
90 | @click.option('--notify', '-n', default=False, is_flag=True) |
||
91 | @click.option('--listen', '-l') |
||
92 | @click.option('--connect', '-c') |
||
93 | @click.option('--profile', |
||
94 | default='disable', |
||
95 | type=click.Choice(['ncalls', 'tottime', 'percall', 'cumtime', |
||
96 | 'name', 'disable'])) |
||
97 | @click.option('config_file', '--config', type=click.Path(exists=True)) |
||
98 | @click.option('--detach/--no-detach', default=True, is_flag=True) |
||
99 | @click.pass_context |
||
100 | def main(ctx, prog, notify, listen, connect, profile, config_file, detach): |
||
101 | """Entry point.""" |
||
102 | |||
103 | if detach: |
||
104 | exit_code = detach_proc() |
||
105 | |||
106 | address = connect or listen |
||
107 | |||
108 | if address: |
||
109 | import re |
||
110 | p = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\:\d{1,5})?$') |
||
111 | |||
112 | if p.match(address): |
||
113 | args = ('tcp',) |
||
114 | kwargs = {'address': address} |
||
115 | else: |
||
116 | args = ('socket',) |
||
117 | kwargs = {'path': address} |
||
118 | |||
119 | if connect: |
||
120 | # connect to existing instance listening on address |
||
121 | nvim = attach(*args, **kwargs) |
||
122 | elif listen: |
||
123 | # spawn detached instance listening on address and connect to it |
||
124 | import os |
||
125 | import time |
||
126 | from subprocess import Popen |
||
127 | os.environ['NVIM_LISTEN_ADDRESS'] = address |
||
128 | nvim_argv = shlex.split(prog or 'nvim --headless') + ctx.args |
||
129 | # spawn the nvim with stdio redirected to /dev/null. |
||
130 | dnull = open(os.devnull) |
||
131 | p = Popen(nvim_argv, stdin=dnull, stdout=dnull, stderr=dnull) |
||
132 | dnull.close() |
||
133 | while p.poll() or p.returncode is None: |
||
134 | try: |
||
135 | nvim = attach(*args, **kwargs) |
||
136 | break |
||
137 | except IOError: |
||
138 | # socket not ready yet |
||
139 | time.sleep(0.050) |
||
140 | else: |
||
141 | # spawn embedded instance |
||
142 | nvim_argv = shlex.split(prog or 'nvim --embed') + ctx.args |
||
143 | nvim = attach('child', argv=nvim_argv) |
||
144 | |||
145 | from .gtk_ui import GtkUI |
||
146 | config = load_config(config_file) |
||
147 | ui = GtkUI(config) |
||
148 | bridge = UIBridge() |
||
149 | bridge.connect(nvim, ui, profile if profile != 'disable' else None, notify) |
||
150 | |||
151 | if detach: |
||
152 | sys.exit(exit_code) |
||
153 | |||
157 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.