After adding check-module it fixed the white space issue when I ran tslint-fix
whitespace: ["check-module",etc]
Before
import {someone} from 'module';
after
import { someone } from 'module';
But still I had an issue with alias name:
Current:
import {default as sample, somesample } from './models/samples';
Expected:
import { default as sample, somesample } from './models/samples';
Will any White Space rule fixes this?
Well this may be a bug of ts-lint, or some miss-configuration, you can try another syntax to see if works for you:
import sample, {someone} from './models/sample'
Related
I am trying to build a telegram bot, I have just reproduce the code:
from telegram.ext import MessageHandler
from telegram.ext import filters
from telegram.ext import Application
from telegram import Update
from telegram.ext import ContextTypes
from decouple import config
def testFunc (update: Update, context: ContextTypes.DEFAULT_TYPE):
print('Hi')
def main():
BOT_TOKEN = config('TELE_BOT_API_KEY_2')
application = Application.builder().token(BOT_TOKEN).build()
application.add_handler(MessageHandler(filters.Text & ~filters.Command, testFunc))
application.run_polling()
if __name__ == '__main__':
main()
The error this code shows is:
Bot\AsyncAdvanceBot\test3.py", line 16, in main
application.add_handler(MessageHandler(filters.Text & ~filters.Command, testFunc))
TypeError: bad operand type for unary ~: 'type'
I am using python-telegram-bot api v20.x
I know this might be a naive problem that I might be missing.
Thanks!
I tried changing the code to different format but it doesn't work.
I got it! It was as I said naive error. I was not thinking straight😅
I have seen the document even earlier and was only focusing on making filters.Command to filters.COMMAND, but forgot to change filters.Text to filters.TEXT.
just replaced
filters.Text & ~filters.Command
with
filters.TEXT & ~filters.COMMAND
pylint is not producing the expected convention warning messages for whitespace non-conformances.
python 3.6.8
pylint 2.13.5
using this test script :
from __future__ import print_function
import os, sys
import logging
from .. import views
class DoSomething(SomeCommand) : # space before colon !
def __init__(self):
for i in range(1,11): # no space after comma !!
if self.number == i:
print("matched")
else:
print ('not matched') # space before paren !!!
def check_user(self):
if self.user: return True
else : return False # spaces before colon !
results from pylint check :
PS C:\Users\PycharmProjects\coding_standard\src> pylint test_script.py
************* Module test_script
test_script.py:18:0: C0304: Final newline missing (missing-final-newline)
test_script.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test_script.py:3:0: C0410: Multiple imports on one line (os, sys) (multiple-imports)
test_script.py:5:0: E0402: Attempted relative import beyond top-level package (relative-beyond-top-level)
test_script.py:7:0: C0115: Missing class docstring (missing-class-docstring)
test_script.py:7:18: E0602: Undefined variable 'SomeCommand' (undefined-variable)
test_script.py:16:4: C0116: Missing function or method docstring (missing-function-docstring)
test_script.py:17:8: R1703: The if statement can be replaced with 'return bool(test)' (simplifiable-if-statement)
test_script.py:17:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
test_script.py:17:22: C0321: More than one statement on a single line (multiple-statements)
test_script.py:7:0: R0903: Too few public methods (1/2) (too-few-public-methods)
test_script.py:3:0: W0611: Unused import os (unused-import)
test_script.py:3:0: W0611: Unused import sys (unused-import)
test_script.py:4:0: W0611: Unused import logging (unused-import)
test_script.py:5:0: W0611: Unused import views (unused-import)
Based on the docs I would expect to see C0326 messages for the commented lines.
I am using this as the reference for the conditions to be identified by C0326:
http://pylint-messages.wikidot.com/messages:c0326
Any suggestions to T/S this ?
Based on comment from #DylanLee ...
If I did it is truly by accident. I am not (knowingly) using any kind of config file to disable messages. Based on your comment, I ued the command line option:
$pylint --list-msgs-enabled
, which produces a list ...
Enabled messages:
...
multiple-statements (C0321)
superfluous-parens (C0325)
mixed-line-endings (C0327)
unexpected-line-ending-format (C0328)
wrong-spelling-in-comment (C0401)
...
Disabled messages:
raw-checker-failed (I0001)
bad-inline-option (I0010)
locally-disabled (I0011)
file-ignored (I0013)
suppressed-message (I0020)
useless-suppression (I0021)
deprecated-pragma (I0022)
use-symbolic-message-instead (I0023)
So, it is not obviously being disable, but is not included in the enabled list !
Maybe some updates to pylint that is suppressing that specific message ?
bad-whitespace has been removed from pylint in 2.6. You should use an autoformatter like black and pre-commit to handle this automatically.
See : https://pylint.pycqa.org/en/latest/whatsnew/2.6.html?highlight=bad-whitespace#other-changes
bad-continuation and bad-whitespace have been removed. black or another formatter can help you with this better than Pylint
I am still learning python but got stuck here:
from pathlib import Path
import os
import shutil
p = Path.home()
shutil.copy(p / 'G:\souce.txt', p / 'G:\dest.text')
The error is:
shutil: shutil
Anomalous backslash in string: '\s'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Anomalous backslash in string: '\d'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Module 'shutil' has no 'copy' memberpylint(no-member)
Not able to go for the next step. So any suggestions please.
You can just do:
import shutil
shutil.copy('G:\souce.txt', 'G:\dest.text')
I am prototyping a meta model on top of proto3. To generate domain specific boilerplate as the go proto3 extension syntax is ridiculously expressive. My domain proto files depend on meta.proto which contain the extensions.
I can compile the these to go. When including the meta.proto file the generated go ends up with the following include block:
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "google/protobuf" <--- this import does not exist !!
My extension file has the following structure(based off this):
syntax = "proto2";
package "...";
option go_package = "...";
import "google/protobuf/descriptor.proto"; <--- this causes the import
// message MyExtensionClass ...
// message MyExtensionField ...
extend google.protobuf.MessageOptions {
optional MyExtensionClass class = 50000;
}
extend google.protobuf.FieldOptions {
optional MyExtensionField field = 50001;
}
I know the solution is likely very simple, the google/protobuf include is meant for C++ generation.
In my workspace the included package should be "github.com/golang/protobuf/protoc-gen-go/descriptor"
Poor mans solution. Not ideal, directing it to the relevant go import works:
sed -i '' -e 's/import google_protobuf \"google\/protobuf\"/import google_protobuf \"github.com\/golang\/protobuf\/protoc-gen-go\/descriptor\"/g' pkg/domain/proto/extensions/*.pb.go
I have created a pygments style, which uses the same colors as xcode, and named it xcode.py:
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic
class xcodeStyle(Style):
default_style = ""
styles = {
Text: '#000000',
Comment: '#008426',
String: '#D92823',
Number: '#2F2ECF',
Keyword: '#C22A9C',
Name.Class: '#753EA3'
}
I tried placing it in /Library/Python/2.7/site-packages/pygments/styles but when I list the available styles with
from pygments.styles import get_all_styles
styles = list(get_all_styles())
print styles
my style doesn't get recognized. Any ideas why?
Indeed, it's not quite clear how to add custom pygments style from their official docs. But I've figured it out after a while.
Sphinx has a conf.py parameter https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-pygments_style
Which could be a fully-qualified name of a custom Pygments style class. This is what we should use.
OK, the steps:
Create a python module, e.g. my_fancy_style.py with your style class MyFancyStyle
Put my_fancy_style.py in the same dir where your conf.py is located.
Uncomment/write in conf.py lines, so sphinx will be able to find your class
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
# ...
pygments_style = 'my_fancy_style.MyFancyStyle'
That's it!